Fallback from CDN to local jQuery
hanselman.com
hanselman.com
A much better architecture would be to serve JavaScript from your server by default, but allow for distributed content-based caching. For example, your script tag could look like this
<script src="some.js" hash="ha3ee938h8eh38a9h49ha094h" />
The hash would be calculated based on the content of the file. The browser then could fetch it from whatever source it wants. Users could cache stuff locally (across websites), without needing to dial into a CDN every time. You could even use a torrent-like network for distributed delivery of popular script libraries.
I think it would take Mozilla or Apple to push this. Google probably has too much skin in the CDN-info-gathering game.
If you host some stuff on server 1 and some stuff on server 2, and you need both to function, then you have two points of failures.
This is kind of a simple argument, increasing the number of "points of failure" doesn't, or shouldn't increase your odds of "failing" more. Adding cache layers and CDNs may add "servers" to your architecture but should also be done in way to reduce overall downtime.
I should also mention that all this happens only on first load. We embed etags in the URLs and use far off cache control expires dates, so subsequent page loads get the JS and CSS from the browser's cache.
Conversely, you control what shows up on your own private CDN, like CloudFront. Sure, there may be downside outside of your control, but nobody is going to be able to alter the resources there without your permission.
> Conversely, you control what shows up on your own
> private CDN, like CloudFront. Sure, there may be
> downside outside of your control, but nobody is going
> to be able to alter the resources there without your
> permission.
Well, CloudFront could, since they control the machines that your users are connecting to.To me, there's a trade-off I've chosen, and while I'm not 100% comfortable with having the availability of my site depend on Google - "repugnant" is _way_ to strong a word to describe the downside to the pragmatic choice I've made.
Besides, in bigger projects jquery is only a small part of the whole js stack. I've been using these jquery cdns for years, now I just pack it together with everything else uglified. There are so many jquery versions in use around there right now I don't feel I gain anything by caring about the chance that this particular 30kb will be cached by some percentage of users.
Also, I don't understand why people feel so strongly about reposting this "document.write" method everywhere, which I found in some cases made my page disappear at load time. You can do the same thing using regular DOM methods, and you get more control over the process.
If you insert the script using a script it's execution is delayed until after DCL
Pros:
+ I can cache it for a very long time, so all my returning visitors don't have re-download it. I was very surprised to see that CDN's jquery had a very short 'Expire' headers
+ If my server is up and users can open a web page - there's a very high chance that the .js file will load as well.
+ I can combine different jquery libraries/plugins into one file, so my page can load MUCH faster
Cons:
- It might load a little more slowly, because it's not on CDN.
Am I missing something?
import 'http://developer.yahoo.com/modules/yui3.js' as YUI;
wish it was: import ['http://developer.yahoo.com/modules/yui3.js', '/libs/yui3'] as YUI; try:
import simplejson as json
except ImportError:
import json
So it might be worth contacting the committee and expressing that.One thing is that only about 1% have the specified version you use on your site.
No, but I think the parent was making the case for combining everything into a single file (jQuery + app) which has benefits in reducing number of HTTP requests, especially important on mobile for example.
>> The point of a CDN is local distribution, not just load balancing.
Personally, I build web-apps for UK customers, and host in the UK, so this is a non-issue. I suspect the same is true for a lot of people building complex web-apps (i.e. apps complex enough that you should care about your build process).
>> You also get to share a cache with other sites; if you point to jQuery on Google's CDN, and the visitor has been to any other site using that CDN, they already have the file cached.
Not really true, they have to have hit another site that has uses that exact version of jQuery in order to have it cached. There was a study done recently that illustrated this was very unlikely. I wish I could link to it, but all I can tell you is Alex Sexton referenced it on the Shoptalk podcast [1].
Edit: Another commenter has now referenced the survey in question [2].
[1] http://shoptalkshow.com/episodes/061-with-alex-sexton/
[2] http://www.stevesouders.com/blog/2013/03/18/http-archive-jqu...
What I prefer to do is have a common bundle for the JS used on every page, bundles for each distinct type of page, and separate polyfills for old browsers. This improves your initial cold-cache load time for every page, avoids penalizing new browsers because other people use antique browsers and avoids cache churn by invalidating the entire bundle every time you change anything in one JS file.
And then, served via CDN.
Is there a good compendium of modern popular toolkits?
My fear was more on the server-side. Can we accomplish this without further butchering the head from the standard? I can't see all browsers adopting this or it becoming a standard without a major sponsor. And like someone else mentioned, we can get about the same benefits from aggressive caching. I agree for the most part.
Don't get me wrong. I love Google. I love what they do to make the web faster with their hosted libraries[1]. Correct me if I am wrong but caching the libraries from Google only helps if the the server specifies they want that particular file from Google (I'd imagine it would be a gaping security hole any other way). My thought is whether it is possible to just declare something like 1.9.1.min.jQuery.com and have the browser just recognize it and say "Oh yes I have that. No need for a server round trip. You're welcome." or "No, I don't understand what you're talking about. Give me an address so I can fetch it."
Is it even worth it? jQuery 1.9.1 minified is ~90 kB, so we're probably just trying to shave off tens of milliseconds at the most. I bet we all have fruits hanging lower than this to worry about it. Another thing is that it will probably have to be a vendor-specific meta tag (as I don't see everyone getting aboard this, if anyone) in the header which I don't know is a good thing.
[1] https://developers.google.com/speed/libraries/
*I believe Mozilla Firefox has also started silent updates. It'd be nice to see how quickly users update when a new build gets pushed out.
<script
src="my-copy-of-jquery.1.9.2.js.min"
cannonical-uri="https://jquery.com/jquery.1.9.2.js.min"
hash="SHA1-blablabla"
></script>
With this setup:1. Old browsers could work as before
2. New browsers could download your resource and cache it with the cannonical-uri and calculated (not declared!) hash as cache key (no dependency on third party CDNs)
3. New browsers could serve this resource from cache if it had downloaded it before with matching cannonical-uri AND hash, disregarding src and host
The hash would make sure that the jquery the user downloaded from whereever would indeed be the same jquery you are serving up.
----
Going back to your original idea, browsers could absolutely come with prepopulated caches for such resources, but they might as well fill these caches on demand.
The important thing in both cases would be to allow shared caching between sites without forcing everybody to agree on which CDN is the most pleasing. Notice that the cannonical-uri is only a name, it is not supposed to be dereferenced.
>>The important thing in both cases would be to allow shared caching between sites without forcing everybody to agree on which CDN is the most pleasing. Notice that the cannonical-uri is only a name, it is not supposed to be dereferenced.
Yes, you put it much better than I could have. Thank you!
Like 4ea5b90bdb6f54a9b050cfd8dd19083d.js
I mean, for instance, you couldn't load that FIRST CDN jquery as async, because you need the browser to block on it so your NEXT script tag (which also can't be loaded async, naturally, cause it has a document.write in it) can check to see if it was loaded.
Maybe it's just some feature of bootstrap I don't know about, but I'm not even sure what to go looking for because I'm not sure what you're suggesting is built into bootstrap. Built into the Javascript parts of Bootstrap somehow? What is, exactly?
Also remember to always use the https URL for the assets, whenever able.
There's still a significant benefit in just storing the file closer to the end-user, rather than in a single central location, as the CDN is likely to have both lower latency and have higher bandwidth than the source website.
Now, if your file was so unique and rarely accessed that it wouldn't even be cached on the CDN, then I'd agree with those findings.
[1] http://stackoverflow.com/questions/4303633/preventing-secure...