代码之家  ›  专栏  ›  技术社区  ›  A_M

Expires/Cache控制头有问题

  •  1
  • A_M  · 技术社区  · 14 年前

    我使用的是Apache2.2.16。

    我的htdocs文件夹中有以下HTML文件:

    <html>
     <link media="screen" type="text/css" href="/css/test.css" rel="stylesheet" />
     <body>XXXX</body>
    </html>
    

    我正在尝试在浏览器中缓存CSS文件,这样除了第一次加载页面之外,它就不会再对它发出请求。

    我的httpd.conf文件中有以下内容:

    <LocationMatch "\.(css)$">
     Header set Cache-Control "max-age=2592000"
     Header set Expires "Thu, 15 Apr 2020 20:00:00 GMT"
     Header unset Last-Modified
     Header set Content-Type text/css
     Header unset ETag
    </LocationMatch>
    

    以下是Firebug报告的我的响应头:

    Date    Mon, 29 Nov 2010 10:48:49 GMT
    Server  Apache/2.2.16 (Win32)
    Accept-Ranges   bytes
    Content-Length  18107
    Cache-Control   max-age=2592000
    Expires Thu, 15 Apr 2020 20:00:00 GMT
    Content-Type    text/css
    Keep-Alive  timeout=5, max=97
    Connection  Keep-Alive
    

    我读过一些关于设置缓存头的文章,但是我只是看不到如何使其工作。

    任何建议都非常感谢。

    1 回复  |  直到 14 年前
        1
  •  0
  •   futtta    14 年前

    在手动设置expires&cache控件的配置中,我也看到过类似的问题。只是让 mod_expires 做“重担” 可以 已经解决了这些问题?