by lrem · 13y ago · 0 comments
But yes, your point is valid. Also, jquery is so ubiquitous that I see no reason to steer clear of it. If you use a CDN version of it, it's most probably already in client's cache.
(No, I don't have data on mine, I don't even work in this field.)
http://w3techs.com/blog/entry/jquery_now_runs_on_every_secon...
Of the top 10k sites 58.8% use jQuery. That's good!
But only 26.6% use a cdn. Leaving only 15.6%. That's bad...
But 94.2% use Google's. Which is still 14.7%! That's good!
http://www.stevesouders.com/blog/2013/03/18/http-archive-jqu...
But only 1% use the newest version of jQuery. Leaving only 0.15%. That's bad...
http://www.quora.com/User-Behavior/How-many-websites-does-an...
But users visit on average 89 sites per month. Which gives us 12.5%. That's good!
http://stevesouders.com/cache.php
But default browser cache sizes are small. That's bad...
http://www.webperformancetoday.com/2013/06/05/web-page-growt...
But the average website is about 1MB so with a 50MB cache about 50 sites can be cached. Which leaves about 7.2%. That's... OK?
OK. So I don't actually know if a cdn cache hit is all that likely, but the situation is a bit worse, and a bit better than most people think.
Of course, using a cdn is still better than hosting yourself. If you bundle your jQuery then every time your site updates it needs to be redownloaded. If you serve it seperately on your domain, you won't have the distribution benefit of a cdn.
Should you use Google's cdn instead of a different commercial cdn provider that's faster? In that case I'm not sure.
The basic gist is that there is great fragmentation in the cache eco-system, and so there is no guarantee that the user actually has the version of jQuery cached that you are requesting. Alex Sexton brought up in a talk at jQueryTO that there are also the time for the DNS request itself to consider in any discussion of speed, if you concatenate/minify your code it will eliminate a DNS request.
Resources discussed in that page: http://statichtml.com/2011/google-ajax-libraries-caching.htm... http://www.stevesouders.com/blog/2011/08/17/http-archive-nin... http://www.stevesouders.com/blog/2013/03/18/http-archive-jqu...
The end conclusion was that for H5BP it didn't make sense to remove the CDN reference, but for your own site it might - you should test it and see. It also depends on your audience (will the CDN move the files closer geographically?).
In the end, ~40k (gzipped) is not going to make or break your website's performance.
It's always better to use a CDN because:
1. It has a chance to be already cached (specially if you use Google's CDN).
2. All browsers nowadays do 6 parallel requests per host. So using DNS prefetching with `rel=dns-prefetch` will be faster.
3. If you bundle jQuery with your site's JS files, every time you change a single JS file of your own, your users will be forced to re-download your bundled jQuery. Seems pretty inefficient to me.