我有一个使用GWT & SmartGWT
开发的应用程序。目前主机页面已缓存在浏览器中,我不想这样做。我想阻止主页(html页面)不要在浏览器中缓存。我尝试添加一些标签
<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"/>
如何实现这一点。任何想法?
答案 0 :(得分:0)
试试这个:
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
答案 1 :(得分:0)
您确定,缓存的“主页”存在问题,而不是缓存的javascript?
如果html页面确实存在问题,您可以在Web服务器中添加必要的标题。
如果使用“ nochache ”名称缓存javascript文件时出现问题,标准解决方案是在web.xml中添加过滤器。
答案 2 :(得分:0)
下面是Filter类,以防止从GWT编译器缓存 nochache 文件。将index.html添加到if语句并在web.xml中激活Filter
import java.io.IOException;
import java.util.Date;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* {@link Filter} to add cache control headers for GWT generated files to ensure
* that the correct files get cached.
*
* @author See Wah Cheng
* @created 24 Feb 2009
*/
public class GWTCacheControlFilter implements Filter {
public void destroy() {
}
public void init(FilterConfig config) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException,
ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestURI = httpRequest.getRequestURI();
if (requestURI.contains(".nocache.")) {
Date now = new Date();
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setDateHeader("Date", now.getTime());
// one day old
httpResponse.setDateHeader("Expires", now.getTime() - 86400000L);
httpResponse.setHeader("Pragma", "no-cache");
httpResponse.setHeader("Cache-control", "no-cache, no-store, must-revalidate");
}
filterChain.doFilter(request, response);
}