0
votes

My web app is referencing CDN to load libraries like React, ensuring that when the app is visited next time, React will be retrieved from browser cache.

When the user visits my app for the first time, there is big chance that the browser cache already has React fetched from some other CDN (result of visiting other apps also using React loaded from different CDN). The URL for React required for my app would be different, so the resource would be still downloaded. How to avoid that?

If it is possible to access browser cache from code, it would be possible to query by resource name and retrieve the resource containing 'react' and '17' so already existing, cached resource could be used as "React v. 17" when visiting my app for the first time.

Are there any planned/existing standards which would allow to state in runtime: "my app requires React v.17 - please reuse your already cached resource or use the resource with the given url (CDN link)"?

1
What you want to do is not possible. Unless browsers make some sort of Global CDN, doubt it would ever work.epascarello
I agree. Furthermore, this isn't really a problem that needs solving, is it? It will only affect some subset of first-time visitors to the site.user47589
in 2021 if app1 loads dependency x from url A and then app2 wants to load the same dependency x it is not possible to reuse the already-cached x unless app2 loads x from the same url A... it is not possible just to say in runtime: please give me lib x with version 5 - if you have it in cache then reuse it please. if you don't have it then fetch it from url A. Thats funny :)Pavel
The app has no way of knowing that the file hosted at url A is the same as url B. They are different resources. You're trying to solve a non-problem affecting a limited portion of your first-time users, and any "solutions" you come up with can cause other issues. If you want to optimize the loading of your site, Google has published a lot of material on that subject.user47589

1 Answers

0
votes

Not possible - thank you for your comments.

I think this is some kind of issue, because there is no way to prevent the browser from re-fetching already cached external dependencies of web applications on first load. I'm a bit suprised that there is no way to solve this. External dependencies are usually bigger part of the app bundle so in many scenarios this would allow to reduce the payload more than 50%.