4 ms·
A comment on the OP says: > Don’t forget that if you’re loading jQuery from a common CDN like Google’s or Microsoft’s, you’re likely introducing zero network l
by jrochkind1 13y ago
A comment on the OP says:
> Don’t forget that if you’re loading jQuery from a common CDN like Google’s or Microsoft’s, you’re likely introducing zero network latency as the browser will almost certainly have it cached already.
This claim is frequently made, but I’ve also seen many people express skepticism of it. The many different versions of jquery, and several different CDNs, combined with actual typical user behavior patterns, the limited cache capacity of some mobile environments, etc…. it MAY still be true, but I’d really want to see some evidence one way or another before assuming it either way.
It’s not an easy thing to measure though, because we are making claims about “most people’s browsers”, and there’s no easy way to measure other peoples browsers. But is anyone aware of anyone trying to approach it?
Why does it matter? If the "cached in most people's browsers" theory is true, then we would not want to concatenate JQuery into one big JS file (as the OP suggests), and we would not want to customize JQuery to include only the AMD modules actually used (as the OP hints at considering), as either one would prevent cache reuse accross sites.
Me, being skeptical of the theory, I still choose to concatenate (I think it's clearly the way to go), and would consider modular customization in the future if it were more convenient for development workflow or it was for a site where size/speed were an absolute priority.
- kivihiinlane 13y ago> Me, being skeptical of the theory, I still choose to concatenate (I think it's clearly the way to go) I have to agree with you. Seeing how my non techy friends use their not high end mobiles, I've decided to go down that road too. Some of my friends clear cache very frequently, their main point is that images take too much room and this slows device down. Knowing that this is not the case and cheap phones just are slow, they pretty much defeat the whole purpose of cache. I've found that the only way to make web faster for them is to concatenate everything.
- spjwebster 13y agoI did some research on this a few years ago [1], and Steve Souders recently re-ran the test with the latest http archive data [2]. Given the percentages, I'm still not convinced that it makes sense to reference jQuery or any other library from a shared CDN. That said, you also need to be careful with concatenation. It's tempting to go for a 'concatenate everything into one file' approach, but that can be suboptimal. When you've got a large library like jQuery that changes infrequently, concatenating that with your constantly-evolving application code results in your users paying the download cost for jQuery every time you make a change (albeit without the connection overhead). Instead, it make sense for some applications to bundle third party libraries into one file, and the application code into another. As I said in my original article, the most important thing you can do to improve the performance of your site is to measure client-side performance from your real user traffic, establish a baseline and only then try various techniques and see which ones have the greatest impact for your site and your visitors. There are various techniques that /might/ help, and some are more universal than others, but you won't know for sure if a change helped or hindered if you can't look at your stats. [1] http://statichtml.com/2011/google-ajax-libraries-caching.html http://statichtml.com/2011/google-ajax-libraries-caching.htm... [2] http://www.stevesouders.com/blog/2013/03/18/http-archive-jquery/ http://www.stevesouders.com/blog/2013/03/18/http-archive-jqu...
- jrochkind1 13y agoThanks a lot for your data and citations!
- deleted 13y ago[deleted]
- bhousel 13y agoAnd to throw another cargo-culty idea into the mix: If you load resources from multiple domains it will lower your Google pagespeed (and YSlow) score. Which can negatively affect your pagerank. So they say. Another point for the "concatenate everything" team. FWIW, this is the approach that I use. And I probably care about those pagespeed and yslow numbers probably way more than I should.
- wooter 13y ago> If you load resources from multiple domains it will lower your Google pagespeed. This greatly depends on the rest of your content.
- bhousel 13y agoOf course. But I can say with confidence that loading JavaScript libraries from a CDN will drop your pagespeed score.
- wooter 13y agohm.. its been a while since I've investigated the issue. However, I don't think this is the case if the JS is loaded asynchronously faster than the rest of the page. I mean what is JQuery, like 20KB? In my experience, JQuery is downloaded faster than most analytics tags/logic.
- continuations 13y agoWhy does loading from multiple domains lower pagespeed score? Wouldn't loading from multiple domains in parallel improve load time and thus improve pagespeed score?
- thaumaturgy 13y agoThis is just a guess (and so a completely worthless comment), but I'd expect that http pipelining has something to do with it.
- aranjedeath 13y agoThe big issue here on mobile isn't caching, but that unless you've absolutely nailed the caching headers (and omitted! etags), the phone will still burn an entire RTT on checking the file. If the only people you serve are in SF or NYC, that's probably fine. If you want to target anyone anywhere else on earth, get rid of that wasted RTT.
- AdrianRossouw 13y agoOr you could be in a situation where you are trying to demo an app to investors, and you find you don't have proper access to wifi. Or your adsl comes down and you find that over the spotty 3g your app suddenly takes 30s+ just to come up with an error message just due to the google fonts you used. Those two are JUST personal experience in the last 6 months. Last time I brought this up publicly somebody mentioned that most CDN's are blocked in China too. Given my past experience, I can think of no possible benefit that can make the additional fragility introduced in my systems worthwhile. I'm not using CDN's for anything more than the odd jsfiddle in the future.