简体   繁体   English

Web浏览器缓存问题

[英]Web browser cache issue

I have been developing many updates for my website, but many clients are complaining that they didn't get any updates. 我一直在为网站开发许多更新,但是许多客户抱怨他们没有得到任何更新。 When i asked them to clear the browser cache, their problem is solved. 当我要求他们清除浏览器缓存时,他们的问题已解决。 But its difficult for clients with below average computer literacy to clear cache. 但是,对于读写能力低于平均水平的客户而言,清除缓存非常困难。 So is there any way to detect cached data in browsers and reload cache if there's change in my site contents? 那么,如果网站内容发生变化,是否有任何方法可以检测浏览器中的缓存数据并重新加载缓存? I had developed my site on HTML,Angular JS. 我已经用HTML,Angular JS开发了我的网站。

you can use some extensions with your js, css files callings like 您可以在js,css文件调用中使用一些扩展名,例如

<header>
 <link href="MyFolder/my.css?v=1.5">
 <script src="myFolder/my.js?v=1.5">
</header>

v = version you can use a global variable to hold value of version then you can increase version number with your updates v =版本,您可以使用全局变量来保存版本的值,然后可以通过更新来增加版本号

Simply add cache busting. 只需添加缓存清除即可。

Add timestamp 添加时间戳

"?ts=" + new Date().getTime()

or As in your case, for build deployment its better to use version. 或者根据您的情况,对于构建部署而言,使用更好的版本。 Fetch your version number from config file 从配置文件中获取您的版本号

var ver = "?ver=" + config.version;
then you url look like
app.js + ver => app.js?ver=1.0.1

For version number in config you may keep it on client side config or get it from api on first hit and save it. 对于配置中的版本号,您可以将其保留在客户端配置中,或者在第一次命中时从api获取并保存。

If you are using requirejs then its so simple just add value like this: 如果您使用的是requirejs,那么它是如此简单,只需添加如下值:

require.config({ urlArgs: ver});

It will automatically append it in every Js url. 它将自动将其附加在每个Js网址中。

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

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