简体   繁体   中英

How to check if browser cached JS library or not?

I have custom build JS library (which is swiper.js ). Can I check if the browser has its CDN version in the cache before downloading it? Normally it's 130KB but my desired version (contain few fewer functions) is just 70KB so I don't want to add those extra KBs to get it from CDN if the user has not already cached it. Is this possible?

Just for clarity, you decide via your markup(html) as to what file the browser should download. So in the case of checking if there's a previous version of a file that you want to refresh, you can simply add a parameter at the end of the file to make the URL unique such that the browser doesn't use one that's prevously downloaded.

Here's an example link:

swipser.js?version=<version or date saved>

So each time a browser see this, it will not download unless the parameter has changed, or perhaps the user has cleared their cache

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