我已将expires标头添加到我的.htaccess文件中,但它们似乎并没有真正起作用。
在Firefox和Chrome中检查结果时(按F12,选择网络选项并按F5重新加载页面),我注意到我在文件中添加的规则被忽略。
这些是从boilerplate复制的规则:
# ----------------------------------------------------------------------
# | ETags |
# ----------------------------------------------------------------------
# Remove `ETags` as resources are sent with far-future expires headers.
#
# https://developer.yahoo.com/performance/rules.html#etags
# https://tools.ietf.org/html/rfc7232#section-2.3
# `FileETag None` doesn't work in all cases.
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None
# ----------------------------------------------------------------------
# | Expires headers |
# ----------------------------------------------------------------------
# Serve resources with far-future expires headers.
#
# (!) If you don't control versioning with filename-based
# cache busting, you should consider lowering the cache times
# to something like one week.
#
# https://httpd.apache.org/docs/current/mod/mod_expires.html
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 year"
# Data interchange
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rdf+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/ld+json "access plus 0 seconds"
ExpiresByType application/schema+json "access plus 0 seconds"
ExpiresByType application/vnd.geo+json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
# Favicon (cannot be renamed!) and cursor images
ExpiresByType image/vnd.microsoft.icon "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 week"
# HTML
ExpiresByType text/html "access plus 0 seconds"
# JavaScript
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
# Manifest files
ExpiresByType application/manifest+json "access plus 1 week"
ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Media files
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType image/bmp "access plus 1 month"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType image/webp "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# Web fonts
# Embedded OpenType (EOT)
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType font/eot "access plus 1 month"
# OpenType
ExpiresByType font/opentype "access plus 1 month"
# TrueType
ExpiresByType application/x-font-ttf "access plus 1 month"
# Web Open Font Format (WOFF) 1.0
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType font/woff "access plus 1 month"
# Web Open Font Format (WOFF) 2.0
ExpiresByType application/font-woff2 "access plus 1 month"
# Other
ExpiresByType text/x-cross-domain-policy "access plus 1 week"
</IfModule>
这些是浏览器中显示的标题。如您所见,脚本和样式表等组件在一个月后过期,而图像在两个月后过期。
样式表标题:
Cache-Control: max-age=2592000, public
Content-Encoding: gzip
Content-Type: text/css
Date: Tue, 21 Jun 2016 16:06:22 GMT
Expires: Thu, 21 Jul 2016 16:06:22 GMT
脚本标题:
Cache-Control: max-age=2592000, public
Content-Encoding: gzip
Content-Type: application/javascript
Date: Tue, 21 Jun 2016 16:06:22 GMT
Expires: Thu, 21 Jul 2016 16:06:22 GMT
图片标题:
Cache-Control: max-age=5184000, public
Connection: keep-alive
Date: Tue, 21 Jun 2016 16:10:13 GMT
Expires: Sat, 20 Aug 2016 16:10:13 GMT
我能做些什么吗?
答案 0 :(得分:0)
首先,用curl -IL&#34;(URL)&#34;确认。对于Web服务器正在发送的确切标头。
第二,确保你没有&#34;忽略缓存&#34; Chrome中选中了复选框。
第三,从curl,Chrome和Firefox执行此操作时,访问日志对这些请求的说法是什么?
编辑:实际答案是检查过期模块是否实际启用。