如何防止JavaScript缓存?查询字符串方法不起作用 [英] How can I prevent javascript caching? Querystring approach isn't working

查看:41
本文介绍了如何防止JavaScript缓存?查询字符串方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了将版本号或MD5哈希附加到JS src查询字符串的其他方法.

I've seen other approaches that attach a version number or MD5 hash to a JS src querystring.

e.g. <script src='/script/v1/'></script>

但是,当我推送网站的新版本时,我的JavaScript仍在多个浏览器(Chrome,Firefox)中缓存.

However, my JavaScript is still getting cached in multiple browsers (Chrome, Firefox) when I push a new version of my site.

这似乎是其他人已解决的主要问题,而且我似乎在做正确的事情.我怎样才能使它正常工作?

This seems like a major problem that others have solved, and I seem to be doing the right things. How can I get this to work?

推荐答案

我添加了日志消息,并确定querystring方法正在工作.抱歉,不必要的问题.

I added log messages and determined that the querystring method is working. Sorry for the unnecessary question.

但是,在研究中,我发现了一些值得一提的重要点:

However, in researching, I found some important points worth mentioning:

  1. 其中一篇文章建议使用附加了当前时间的查询字符串.您可能不想遵循此建议,因为您的文件将从不被缓存.使用源代码控制版本号或MD5哈希值会更好.
  2. Steve Souders(属于高性能网站著名)指出,某些Web代理从不缓存任何带有查询字符串的内容.因此,版本号应嵌入到文件的路径中,以确保在通过这些代理访问文件时适当地缓存了文件.( http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/)
  1. One of the articles suggests using a querystring with the current time appended. You probably don't want to follow this suggestion as your files will never be cached. Using source control version numbers or an MD5 hash would be better.
  2. Steve Souders (of High Performance Web Sites fame) notes that certain web proxies never cache anything with a querystring. Thus, the version number should be embedded within the path to the file in order to ensure that your files are cached appropriately when accessed through these proxies. ( http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/ )

这篇关于如何防止JavaScript缓存?查询字符串方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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