However, I think this is becoming less common with the increasing popularity of module bundlers like webpack. It's still possible with webpack [3], but it's not as easy as a 'npm i react' and 'import React from "react";'.
That said, a module bundler could easily automatically swap out local modules for modules hosted on CDNs in production builds (with fallbacks in case the CDN is down). I'm a little surprised this doesn't seem to exist yet, at least for webpack.
3. https://webpack.github.io/docs/library-and-externals.html
e.g. <library name="react" version="^5.0"><script src="https://cdn/react-5.0.8.js"></script></library>
import _ from package 'github.com/lodash/lodash/tree/4.8.2';
import $ from package 'jquery.com/version/2.2.0';
Your browser would make the OOB requests and cache the results in a shared directory, which any JS code that's running locally can use. This way, HTTP requests for 3rd-party components shared across websites aren't repeated over and over again for the same libraries. And it could even be extended to CSS: @import package("github.com/twbs/bootstrap/tree/3.3.6");<script src='...' checksum='2fd4e1c67a2d28fced849ee1bb76e7391b93eb12' />
Which would allow the browser to use cached copies of files even if from different domains. Not sure where I saw that.
That attribute is meant to verify resource contents. The strategy of using it as a cache ID is still being discussed, but last I looked into it, there were some cache poisoning concerns.
You might find this thread useful: https://news.ycombinator.com/item?id=10311020
I think what's needed is a heuristic webpack-loader, where you can specify both a self-hosted URL and a cdn-URL. It could work like this:
* Load the CDN version and fallback back to the self-hosted version, if it doesn't exist or takes too long. * In certain cases (probability, origin of request, etc.) load the self-hosted version first, but load the CDN in the background, so it get's cached.