Clear browser cache with query string approach

前提是你 提交于 2019-12-11 10:14:27

问题


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?

回答1:


"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.



来源:https://stackoverflow.com/questions/29393503/clear-browser-cache-with-query-string-approach

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!