web applications - When to use "client-side routing" or "server-side routing"? -
i'm little bit confused this, , feel stupid asking question, want understand it.
so, i'm working client side web framework, backbone, angular or durandal. framework includes routing.
but of course still have server database stuff, , on, has routing.
my question is:
when use "client-side routing" or "server-side routing"?
how "decided" whether routing performed on client side or whether request first sent web server?
i have particularly hard time imagining because client side routing before server ever gets know request.
i'd thankful if explain how these 2 routing systems work together.
p.s.: have not included code samples because i'm not looking answer concerning particular framework, concerning routing process in general.
tl;dr:
- with server-side routing download entire new webpage whenever click on link,
- with client-side routing webapp downloads, processes , displays new data you.
imagine user clicking on simple link: <a href="/hello">hello!</a>
on webapp uses server side routing:
- the browser detects user has clicked on anchor element.
- it makes http request url found in
href
tag - the server processes request, , sends new document (usually html) response.
- the browser discards old webpage altogether, , displays newly downloaded one.
if webapp uses client side routing:
- the browser detects user has clicked on anchor element, before.
- a client side code (usually routing library) catches event, detects url not external link, , prevents browser making http request.
- the routing library manually changes url displayed in browser (using html5 history api, or maybe url hashbangs on older browsers)
- the routing library changes state of client app. example, can change root react/angular/etc component according route rules.
- the app (particularly mvc library, react) processes state changes. renders new components, , if necessary, requests new data server. time response isn't entire webpage, may "raw" data, in case client-side code turns html elements.
client-side routing sound more complicated, because is. libraries make easy these days.
there several upsides of client-side routing: download less data display new content, can reuse dom elements, display loading notifications user etc. however, webapps generate dom on server side easier crawl (by search engines), thereby making seo optimization easier. combining these 2 approaches possible, excellent flow router ssr example that.
Comments
Post a Comment