Is Safari on iOS 6 caching $.ajax results?

前端 未结 25 1398
轮回少年
轮回少年 2020-11-22 09:34

Since the upgrade to iOS 6, we are seeing Safari\'s web view take the liberty of caching $.ajax calls. This is in the context of a PhoneGap application so it is

25条回答
  •  旧巷少年郎
    2020-11-22 10:13

    For those that use Struts 1, here is how I fixed the issue.

    web.xml

    
        SetCacheControl
        com.example.struts.filters.CacheControlFilter
    
    
    
        SetCacheControl
        *.do
        POST
    
    

    com.example.struts.filters.CacheControlFilter.js

    package com.example.struts.filters;
    
    import java.io.IOException;
    import java.util.Date;
    import javax.servlet.*;
    import javax.servlet.http.HttpServletResponse;
    
    public class CacheControlFilter implements Filter {
    
            public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
    
            HttpServletResponse resp = (HttpServletResponse) response;
            resp.setHeader("Expires", "Mon, 18 Jun 1973 18:00:00 GMT");
            resp.setHeader("Last-Modified", new Date().toString());
            resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
            resp.setHeader("Pragma", "no-cache");
    
            chain.doFilter(request, response);
        }
    
        public void init(FilterConfig filterConfig) throws ServletException {
        }
    
        public void destroy() {
        }
    
    }
    

提交回复
热议问题