How to programmatically disable html caching with GWT

感情迁移 提交于 2019-12-24 01:24:13

问题


Is there a way to disable the caching of html pages in the browser with GWT ?

I'd rather avoid using inserting META HTTP-EQUIV="EXPIRES" CONTENT=... in the header of my html pages, and do it programmatically instead - if possible.


回答1:


I'd be surprised, if this is possible (and has any effect) with GWT/JavaScript, because it would mean, that the question if and how long the page will be cached can change dynamically while the user views the page.

But even if it is, it won't work with proxies, because they don't evaluate JavaScript... The same is true for your web server, which should serve the page with that HTTP header.

So if you want to make your caching http-equiv meta tags dynamic, you should probably do that on the application server: Use a Servlet or any dynamic page (could even be PHP, if you want) to generate the HTML page. You could even set the real HTTP header there (e.g. in a Servlet by using HttpServletResponse.setHeader(String name, String value))




回答2:


i would say you can't. however, you can use tricks to always refresh your application by adding parameters on links, for example the URL to your app. a changed parameter is considered as a not-yet-fetched page

so try something like that:

<script type="text/javascript">
document.write("<"+"script src='client/client.nocache.js?today=" + getTime() + "'><"+"/script>");
</script>


来源:https://stackoverflow.com/questions/2558779/how-to-programmatically-disable-html-caching-with-gwt

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