使用查询字符串方法清除浏览器缓存 [英] Clear browser cache with query string approach

查看:133
本文介绍了使用查询字符串方法清除浏览器缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在服务器上推送更新的javascript文件时,我需要清除浏览器缓存。一个简单的答案就是使用下面的查询字符串技术。

 < script type = text / javascript src = /js/myjsfile.js?{我的文件版本}>< / script> 

可以,但是


  1. 我是否需要在应用程序的每个
    页面的每个脚本标记上执行此操作?

  2. 我可以在主屏幕上执行此操作吗,例如从
    开头加载的登录名,并且我认为这将用新文件清除缓存的文件,
    可以正常工作吗?


解决方案

我需要在应用程序每个页面的每个脚本标记上执行此操作吗?



是的。缓存基于文件的url,包括那些额外的参数。

添加这些参数实际上并不会从浏览器的缓存中删除文件,而是或多或少地将其视为新的不同文件。 / p>

这也回答了第2点,因为必须在所有页面上都这样做,所以不能仅在一页上做到这一点。


I need to clear browser cache when I push an updated javascript file on server. A simple answer would be to use below technique of query string.

<script type="text/javascript" src="/js/myjsfile.js?{my file version}"></script>

It would work but

  1. Do I need to do this on every single script tag of every single page of my application?
  2. Can I do this at main screen like login which loads at the beginning and I assume that would clear the cached file with new one, would it work?

解决方案

"Do I need to do this on every single script tag of every single page of my application?"

Yes you do. The cache is based on the file's url, including those extra parameters.
Adding those parameters doesn't actually remove the file from the browser's cache, it more or less sees it as a new, different file.

This also answers point 2, since having to do it on all pages means you can't do it on only one page.

这篇关于使用查询字符串方法清除浏览器缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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