admin管理员组文章数量:1327473
Is there any workaround to auto clear the cache as we update the javascript code? It always happen where when I do the script code changes, from other user device, they won't be able to see the new update of the website because their browser is still reading the old script and they will see this as a bug since they do not know about this cache stuff. I have to mention the cache every time when there is an update made which is giving a bad experience to the user.
Usually for an image, I will set some additional unique id from the get method inside the url so that the website is able to read the latest update. But for javascript / jquery, I wonder if there is any kind of code to force the browser to read the new update instead of manually clearing the cache.
Is there any workaround to auto clear the cache as we update the javascript code? It always happen where when I do the script code changes, from other user device, they won't be able to see the new update of the website because their browser is still reading the old script and they will see this as a bug since they do not know about this cache stuff. I have to mention the cache every time when there is an update made which is giving a bad experience to the user.
Usually for an image, I will set some additional unique id from the get method inside the url so that the website is able to read the latest update. But for javascript / jquery, I wonder if there is any kind of code to force the browser to read the new update instead of manually clearing the cache.
Share Improve this question asked Oct 11, 2020 at 8:23 EmeraldEmerald 4092 gold badges8 silver badges19 bronze badges 1- Try forcing no-cache on your page: Disable browser caching – ATD Commented Oct 11, 2020 at 8:27
2 Answers
Reset to default 2You have 3 options:
- Put this in the head section of your html page :
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
This will make your app to not cache anything at all ( at least you can keep it during development)
Use hard refresh for example ctrl+f5 if you are using chrome every time you reload.
Use a Cache killer plugin for your browser. There's a bunch of them out there, you just install them and enable them whenever you want.
You can add a dummy unique id for you javascript. (eg, /javascript.js?id=123)
本文标签: javascriptAuto clear cache from browserStack Overflow
版权声明:本文标题:javascript - Auto clear cache from browser - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742209208a2433390.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论