by rcsorensen · 12y ago · 0 comments
If you love your users, give them HTML and let the Javascript enhance it.
Projects like Facebook's React ( http://facebook.github.io/react/docs/top-level-api.html#reac... ) and Rendr (https://github.com/rendrjs/rendr/) let you use server rendering as well as the single page technologies on the client side.
Sure, that requires jQuery, but most "normal" sites require jQuery, too.
And now your poor little mobile user has to wait for the page to download, then to execute javascript, then to wait for the API response, then wait for the DOM to update.
Or you could put it in the HTML, and then they just have to wait for the page to download.
Give the full html of the first page, load the JS necessary. You get the best of both worlds.
On the first request, the client receives a rendered html page, gets to read the page, then JS functionality is attached.
On any subsequent pages, you do a simple JSON request and update the DOM.
The approaches come together without sacrificing anything. You get to write a single code base using JS (with a node.js backend doing string manipulation so it doesn't even need a DOM), the user gets a page without having to wait for external resource loads, and all page transitions past that are a simple data-fetch away.
You have two choices when taking an SPA approach:
1) Give your users a webpage that is usable, readable, and navigable as soon as they get it.
2) Give your users the skeleton of a webpage that they then have to accept the latency of javascript parsing and execution, and then the latency of data fetches.
we have the ability to do #1.
If you use the right technology, you can give a usable application out of the gate without waiting and use JSON data fetches for every subsequent request.
The reverse is also frequently true: if client rendering can improve cacheability or reduce the data going over the wire the radio savings will pay for a LOT of text updates. Similarly, if you can transfer a large listing without creating thousands of DOM nodes the results can be a wash depending on exactly how much data, the browser, etc.
There isn't a single right answer here - it really depends on the application and good analysis.