Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why use javascript routing?

There seem to be many libraries and packages (Crossroads.js, etc.) which support this javascript routing functionality, but I'm having trouble understanding a scenario where this is valuable.

Anyone care to go soup-to-nuts on situations where this is useful?

My background is with ASP.NET (web forms) programming and some amateur javascript/jquery.

like image 461
skeej Avatar asked Feb 01 '12 20:02

skeej


2 Answers

It gives you option to handle client behavior without having to reload whole page as if with cases when you'd be handling routing server side.

It opens up possibilities for way more responsive and interactive designs as instead of reloading whole page each time route changes you are able to rerender only the portion of the website that changs for a given route. At the same time it helps reducing the load on the server as you reduce the client server communication to sending only the data required to display a page for client to handle it (render views etc.)

Thanks to using backbone.js or other mvc(-like) frameworks you are able to reduce your server to expose just the REST API for working with and receiving data without having to handle the rendering and you are passing some - or even most at times - of the logic to the client.

Most of the web apps nowadays are taking advantage of client-side routing - anything from GMail to twitter.

like image 133
Tom Tu Avatar answered Sep 29 '22 17:09

Tom Tu


OK- I think I understand it better now. It's just a layer of abstraction between a function caller and callee. Instead of attaching a hardcoded dependency between the caller and callee, you can introduce a routing system which will connect the two based on some configuration and provide additional functions like validation, or binding multiple callees to a caller. Then you can reference your actions with restful handles (eg "/getCoffee/decaf") which can also be dynamically constructed (since they're just strings).

I'm still pondering the relative benefits of a routing scheme vs creating a custom event.

like image 40
skeej Avatar answered Sep 29 '22 19:09

skeej