3 ms·
Javascript is great for making more efficient sites. Here's why: 1) Static resources can be cached on a CDN and composited on the client instead of an overload
by EGreg 13y ago
Javascript is great for making more efficient sites. Here's why:
1) Static resources can be cached on a CDN and composited on the client instead of an overloaded app server
2) You can load data instead of heavy and repetitive HTML over the wire
3) You can cache the data in the client and re-use it later, making for snappier interfaces
That said, you have to watch out for URLs. Just because you can write everything with javascript doesn't mean you should break URLs. And of course, crawlers other than google's crawler will probably not be able to execute your JS.
- camus 13y ago1/ Because you cant cache static resources on a CDN without javascript ? 2/ Because you cant load light html over the wire ? 3/ Because you cant cache html pages client side ?
- EGreg 13y agoAre you serious? 1. The browser requests CDN resources directly and Javascript is used to combine those static files into something that the user sees. Since the code is executing on the client, the app server is not overloaded. 2. Suppose you have a list of 20 items. You could either output HTML with all the tags already rendered for each of the 20 items, or you could output a JSON array with 20 objects, which is much less on the wire. 3. If you are rendering stuff on the client and only fetching data for it (which is what modern Javascript MVC frameworks let you do) then you can cache that data and re-use it. Caching entire HTML pages is at a much lower level of granularity that caching each piece of data you get from the server, and reassembling it in different ways.
- sergiosgc 13y ago1. Use a CDN that supports ESI, like CloudFront. 2. It's not that much of a difference, after gzipping, which you surely already do. 3. See number 1. Moreover, in the end, you'll get a less heavy document to be processed by the browser. I swear my all bells and whistles i7 X1 Carbon still struggles on some javascript-heavy sites.
- EGreg 13y agoPlease do elaborate on 1 :)
- steveklabnik 13y agohttp://en.wikipedia.org/wiki/Edge_Side_Includes http://en.wikipedia.org/wiki/Edge_Side_Includes
- mariusz79 13y ago1 has been possible since the beginning of time. Every modern browser as cache built-in.
- EGreg 13y agoThe browser requests CDN resources directly and Javascript is used to combine those static files into something that the user sees. Since the code is executing on the client, the app server is not overloaded.
- nirvdrum 13y agoI'm actually going fairly tired of sites trying to push everything into the client to free up their servers. I routinely run into sites that easily peg an entire core and/or use > 1 GB RAM. A gross generalization, but if you're not able to tune it on the back-end, you probably can't tune it on the front-end, and you're still making your users suffer.