强制从JavaScript文件中缓存过期 [英] Forcing cache expiration from a JavaScript file

查看:120
本文介绍了强制从JavaScript文件中缓存过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧版本的JS文件缓存在用户的浏览器,过期设置为10年(从那时起,我已经学会了如何设置在我的Web服务器上正确过期标题)。我已经更新了JS文件,我希望我的用户从中受益。




  • 有什么办法可以让我的web服务器强制用户的浏览器清除这个文件的缓存,短服务一个不同名称的JS文件?

  • 将来,如果expires头文件设置不正确(偏执狂),我的JS文件自动过期自己,并强制重新加载之后,例如,一天已经过去了,因为它被缓存?



编辑:理想情况下,我想解决这个问题而不是在托管脚本的页面上改变HTML标记。

解决方案

.. no。



您可以在脚本标记的源地址的末尾添加一些内容。浏览器会把它当作一个不同的文件来处理他们当前的缓存。

 < script src =/ js / something ?的.js版本= 2\" >< /脚本> 

不确定您的其他选项。


I have an old version of a JS file cached on users' browsers, with expiration set to 10 years (since then, I have learned how to set expires headers correctly on my web server). I have made updates to the JS file, and I want my users to benefit from them.

  • Is there any way my web server can force users' browsers to clear the cache for this one file, short of serving a differently named JS file?
  • In the future, if expires headers are not set correctly (paranoia), can my JS file automatically expire itself and force a reload after, say, a day has passed since it was cached?

EDIT: Ideally I want to solve this problem without changing HTML markup on the page that hosts the script.

解决方案

In short... no.

You can add something to the end of the source address of the script tag. Browsers will treat this as a different file to the one they have currently cached.

<script src="/js/something.js?version=2"></script>

Not sure about your other options.

这篇关于强制从JavaScript文件中缓存过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆