简体   繁体   English

强制清除Chrome浏览器缓存

[英]Force to clear cache Chrome

I have a custom JS file with many functions in my MVC4 asp.net application. 我在MVC4 asp.net应用程序中有一个具有许多功能的自定义JS文件。 I marked the JS file as Content and selected Copy Always option in the properties. 我将JS文件标记为Content,并在属性中选择了Always Always选项。 However, I can only view latest changes to that file if I clear the cache by pressing CTRL + F5. 但是,如果我按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. 捆绑可以通过对交付的js内容进行版本控制来提供帮助。 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 您可以做的一件事是,通过在URL末尾附加一些值,使浏览器误以为新的JS文件是另一个文件。

<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. 只需在每个版本中增加XXX,浏览器就会将JS文件视为新文件,并忽略以前版本的任何缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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