【问题标题】:Controlling Cache Expirations控制缓存过期
【发布时间】:2013-02-10 15:22:55
【问题描述】:

通过 Google 网站管理员工具的 PageSpeed 分析器运行我的网页后,它向我报告说我的任何资源都没有被缓存。下面是我的 .htaccess 文件中直接取自 H5BP 的代码。我是否正确假设以下到期设置正确并且我的实现中有问题,或者我是否必须为每个文件名设置明确的到期而不是广泛的概括?

# ----------------------------------------------------------------------
# Expires headers (for better cache control)
# ----------------------------------------------------------------------

# These are pretty far-future expires headers.
# They assume you control versioning with filename-based cache busting
# Additionally, consider that outdated proxies may miscache
#   www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/

# If you don't use filenames to version, lower the CSS and JS to something like
# "access plus 1 week".

<IfModule mod_expires.c>
  ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault                          "access plus 1 month"

# cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
  ExpiresByType text/cache-manifest       "access plus 0 seconds"

# Your document html
  ExpiresByType text/html                 "access plus 0 seconds"

# Data
  ExpiresByType application/json          "access plus 0 seconds"
  ExpiresByType application/xml           "access plus 0 seconds"
  ExpiresByType text/xml                  "access plus 0 seconds"

# Feed
  ExpiresByType application/atom+xml      "access plus 1 hour"
  ExpiresByType application/rss+xml       "access plus 1 hour"

# Favicon (cannot be renamed)
  ExpiresByType image/x-icon              "access plus 1 week"

# Media: images, video, audio
  ExpiresByType audio/ogg                 "access plus 1 month"
  ExpiresByType image/gif                 "access plus 1 month"
  ExpiresByType image/jpeg                "access plus 1 month"
  ExpiresByType image/png                 "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"

# HTC files  (css3pie)
  ExpiresByType text/x-component          "access plus 1 month"

# Webfonts
  ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
  ExpiresByType application/x-font-ttf    "access plus 1 month"
  ExpiresByType application/x-font-woff   "access plus 1 month"
  ExpiresByType font/opentype             "access plus 1 month"
  ExpiresByType image/svg+xml             "access plus 1 month"

# CSS and JavaScript
  ExpiresByType application/javascript    "access plus 1 year"
  ExpiresByType text/css                  "access plus 1 year"

</IfModule>

【问题讨论】:

    标签: html css .htaccess caching html5boilerplate


    【解决方案1】:

    看起来不错。

    要么您没有安装 mod_expires 模块(百万分之一没有),要么其他一些 .htaccesshttpd.conf 指令在其他地方禁用了这些。请使用页面速度工具抓取文件发送的实际标题,然后粘贴。

    【讨论】:

    • 我很确定肯定有另一个 htaccess 文件覆盖它,因为我正在与某人共享测试服务器。不过,我只是想确保我所拥有的一切都是好的。谢谢!
    • 我有完全相同的 .htaccess 文件(甚至包括 cmets。例如“谢谢 Remy”)。但是,我也收到有关未使用浏览器缓存的 seo 分析消息。我如何检查 a) 我是否安装了 mod_expires 和 b) 是否有覆盖?谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 1970-01-01
    • 1970-01-01
    • 2011-11-12
    • 1970-01-01
    • 2010-10-08
    • 2015-11-13
    相关资源
    最近更新 更多