简体   繁体   中英

Browser cache - versioning files - but what if browser uses old version?

Say I have a JavaScript SPA that loads one file X_version1.js into the browser, and that file will be run. What is preventing X_version1.js from accidentally calling a function in X_version0.js that was cached in the browser at an earlier time? Are cached .js scripts not invoked unless they are explicitly invoked and under what circumstances could that happen?

This doesn't seem that far-fetched, because sometimes we use cached versions of jQuery, or whatever, which might not be inside the .js file that is loaded in the most recent server request...

The caching doesn't happen at the method level it happens at the file level.

So if you have

<script src="X_version0.js"></script>

Then the browser goes "ah I've downloaded that before! I'll just return the cached version." But when you change your source to:

<script src="X_version1.js"></script>

The browser hasn't seen that file before and goes and fetches it. At this point nothing in the page says load version0 so the browser doesnt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM