Java 如何使用 JS 或 HTML 以编程方式清除浏览器缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46293447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:18:50  来源:igfitidea点击:

How to clear browser cache programatically using JS or HTML

javascriptjavajqueryjsp

提问by sathish anish

I try to clear the chrome browser cache using Add-ons. I am developing as a site using JSP with java, I need to clear the browser cache for the security reason. I tried many ways to clear the cache but none seems to work. Any ideas? Please let me know..

我尝试使用附加组件清除 chrome 浏览器缓存。我正在开发一个使用 JSP 和 java 的站点,出于安全原因,我需要清除浏览器缓存。我尝试了很多方法来清除缓存,但似乎都不起作用。有任何想法吗?请告诉我..

采纳答案by mrid

There's no waya browser will let you clear its cache. It would be a huge security issue if that were possible. This could be very easily abused - the minute a browser supports such a "feature" will be the minute I uninstall it from my computer.

没有办法浏览器会让你清除缓存。如果可能的话,这将是一个巨大的安全问题。这很容易被滥用 - 浏览器支持这种“功能”的那一刻就是我从计算机上卸载它的那一刻。

What you can do is to tell it not to cache your page, by sending the appropriate headers or using these meta tags.

您可以做的是通过发送适当的标头或使用这些元标记来告诉它不要缓存您的页面。

Source: https://stackoverflow.com/a/8155121/5437621

来源:https: //stackoverflow.com/a/8155121/5437621

回答by Ghanshyam Dekavadiya

Cache.delete()

Cache.delete()

can be used for new chrome, firefox and opera.

可用于新的chrome、firefox 和opera。

try it please in js File

请在 js 文件中尝试

回答by Farhad Bagherlo

  • call window.location.reload(true)for a ctrl+F5 from script.
  • In the new version of browsers Cache.delete()
  • in meta tag
  • window.location.reload(true)从脚本中调用ctrl+F5。
  • 在新版浏览器中 Cache.delete()
  • 在元标记中


<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
  • in jQuery $('html[manifest=saveappoffline.appcache]').attr('content', '');
  • 在 jQuery 中 $('html[manifest=saveappoffline.appcache]').attr('content', '');