Image Not Caching?

有些话、适合烂在心里 提交于 2019-12-13 06:27:27

问题


I'm convinced that certain images on my site are not caching properly. I have set the headers as best I can, but it still seems like they download again every time I hit the refresh button.

For example, a particular image always takes a bit over 1 second to download. This is even after it should be cached. Here are the response headers:

HTTP/1.1 200 OK
Date: Sun, 06 Mar 2011 12:51:52 GMT
Server: Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.7a mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.16
Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT
Accept-Ranges: bytes
Content-Length: 19211
Cache-Control: max-age=630323456, public
Expires: Wed, 03 Mar 2021 12:51:52 GMT
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Content-Type: image/png

Is there anything wrong with this? Thanks.

UPDATE

<FilesMatch "\.(htm|html|php)$">
    Header set Expires "Thu, 01 Jan 1970 00:00:00 GMT"  
</FilesMatch>

回答1:


Your Last-Modified says 1970, and your max-age is 630323456 seconds (19 years). So the file has been 'expired' since 1989, and must be re-downloaded. The browser is doing what it should be doing.

Solution:

  1. Change the Last-Modified to the real Last-Modified (probably some time in the past few years)

  2. Change the max-age to

  3. Remove the Expires header; it is overridden when you also have max-age. See RFC2616 section 14.9.3. Alternatively, delete the Cache-Control header and keep only the Expires header. Either one is fine, but only use one, not both of them.



来源:https://stackoverflow.com/questions/5210644/image-not-caching

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