简体   繁体   中英

Force to clear cache Chrome

I have a custom JS file with many functions in my MVC4 asp.net application. I marked the JS file as Content and selected Copy Always option in the properties. However, I can only view latest changes to that file if I clear the cache by pressing CTRL + F5. I was wondering if there is any other way to clear the browser cache automatically when I deploy the application to the server.

Bundling can help by versioning the delivered js content. Read about it here .

The server cannot instruct the browser to clear the cache for items that are already cached, because the cache prevents the browser from even asking the server about it. Even if you could, there may be other caches in between the server and the client.

One thing you can do is fool the browser into thinking that your new JS file is a different file by appending some value to the end of the URL, eg

<SCRIPT SRC="https://Domain.com/Scripts/MyScriptName.js?version=XXX">

Just increment XXX with each build and the browser will see the JS file as new and ignore any cache of previous versions.

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