简体   繁体   English

浏览器未缓存资源(已设置标题)

[英]Browser not caching resources (headers set)

My JEE6/JSF/primefaces application is available through https (two-way ssl: both server and user certificate required). 我的JEE6 / JSF / primefaces应用程序可通过https(双向SSL:同时需要服务器和用户证书)获得。 I want browsers to cache resources files, so all resources are served with headers: "Cache-Control:public, max-age=2592000" and "Expires:Fri, 19 Dec 2014 07:46:27 GMT"(now+1 month). 我希望浏览器缓存资源文件,因此所有资源均带有标头:“ Cache-Control:public,max-age = 2592000”和“ Expires:Fri,2014年12月19日7:46:27 GMT”(现在+1个月) )。 But still, both recent FF and IE request all js/css/png files on every page and after every refresh (F5). 但是,尽管如此,最近的FF和IE都在每个页面上以及每次刷新后都请求所有js / css / png文件(F5)。 Below are my request and response headers. 以下是我的请求和响应标题。 What am I doing wrong? 我究竟做错了什么?

Request:            GET /javax.faces.resource/primefaces.css.jsf?ln=primefaces HTTP/1.1
Accept:         text/css, */*
Referer:            https://xxxxx.yy/zz/abc.jsf?type=1
Accept-Language:    en-US
User-Agent:     Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding:    gzip, deflate
Host:           xxxxx.yy
DNT:                1
Connection:     Keep-Alive
Cookie:         ServerID=1845; JSESSIONID=Wmsmxxx!-1754822933

Response:           HTTP/1.1 200 OK
Date:               Wed, 19 Nov 2014 07:37:49 GMT
Server:             Apache
Cache-Control:      public, max-age=2592000
Pragma:             public
Expires:            Fri, 19 Dec 2014 07:46:27 GMT
Last-Modified:      Tue, 13 Nov 2012 10:02:34 GMT
X-Powered-By:       Servlet/3.0 JSP/2.2
X-Powered-By:       JSF/2.0
Keep-Alive:         timeout=15, max=100
Content-Language:   en
Connection:         Keep-Alive
Transfer-Encoding:  chunked
Content-Type:       text/css

It will depend on what type of requests have you enabled cache for. 这将取决于您对缓存启用了哪种请求。

Check the following two places to see what gets included in caching Your URL patten must match the requests coming through for the static content. 检查以下两个地方,以查看缓存中包含的内容您的URL模式必须与对静态内容的请求相匹配。

<filter-mapping>
    <filter-name>cache</filter-name>
    <url-pattern>*.xhtml</url-pattern>
</filter-mapping>

The second place would be in the cache filter itself. 第二位将在缓存过滤器本身中。 eg if you have your own cache filter, specify correct type of static content. 例如,如果您有自己的缓存过滤器,请指定正确的静态内容类型。 If you are using out of the box implementation, then i suppose web.xml would take that as argument. 如果您使用的是开箱即​​用的实现,那么我想web.xml会将其作为参数。

if (uri.contains(".js") || uri.contains(".css") || uri.contains(".svg") || uri.contains(".gif")
                || uri.contains(".woff") || uri.contains(".png")) {
            httpResponse.setHeader("Cache-Control", "max-age=" + maxAge);
        }

Here are the details of I have done this: 这是我执行此操作的详细信息:
https://stackoverflow.com/a/35567540/5076414 . https://stackoverflow.com/a/35567540/5076414
Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM