Something is broken about the way javascript works on the web now. A huge fraction of sites run on pretty sizeable javascript libraries such as react, angular, vue plus common supporting pieces (react-router, redux, mobx, etc.. etc..). In the old days you would load your libraries with a CDN link and this meant the browser could cache that resources and reuse it across multiple pages.
In modern JS apps almost everyone is using their own transpilers, bundlers and minifiers so this means that each site is serving some processed form of the same code. This means we're waiting for loads and sending piles of data over the network that are hugely duplicative.
Is there a better way? I think there is and, maybe, it's even something we could do now. I suspect, however, that it will take a slight modification of some of the standards.
The fundamental problem with just all hitting the CDN and caching that is that there are so many different versions of these libraries and, since we would no longer be able to tree-shake the libraries to extract only the pieces we need, that means the browser would have to have basically every live version cached.
But, I think we can do better. These libraries don't change that much between versions so if we could somehow just have the browswer cache diffs we might have a chance. Alright, well there is this Cache api which might let us do what we need (though perhaps a bit inefficiently).
So, what's needed, is a CDN which can serve it's own javascript into something like a service/web worker and then load the library in response to a request from the page code. That CDN javascript would need to be able to check which versions of the library were cached in the browswer so it could send a header to the CDN indicating what kind of diff it needs. Then the browswer would have to apply that diff before running the script.
I suspect that this is either unworkable or too slow as it is. But, it seems like the kind of thing that would offer huge speed benefits (especially if browsers came preloaded with some of this cache) if we could get it working. More importantly, it could let browsers retain these libraries in higher performance partially compilled form.