【问题标题】:How to specify a cache validator for PNG files in .htaccess?如何在 .htaccess 中为 PNG 文件指定缓存验证器?
【发布时间】:2013-06-10 21:26:34
【问题描述】:

我想在用户缓存中缓存网站上的所有图像和视频至少一个月,以加快加载过程。

但是http://gtmetrix.com 速度报告给了我以下错误:

以下资源缺少缓存验证器。资源 不指定缓存验证器无法有效刷新。 指定 Last-Modified 或 ETag 标头以启用缓存验证 以下资源:

// 此处列出的当前在我的页面上的所有 *.png 文件 //

到期时间:

### CACHING ###
<IfModule mod_expires.c>
  ExpiresActive on
  ExpiresDefault "access plus 1 month"
# cache.appcache needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)
  ExpiresByType text/cache-manifest "access plus 0 seconds"
  ExpiresByType text/html "access plus 0 seconds"
  ExpiresByType text/xml "access plus 0 seconds"
  ExpiresByType application/xml "access plus 0 seconds"
  ExpiresByType application/json "access plus 0 seconds"
  ExpiresByType application/rss+xml "access plus 1 hour"
# media: favicon, images, video, audio
  ExpiresByType image/x-icon "access plus 1 month"
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType image/jpg "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType video/ogg "access plus 1 month"
  ExpiresByType audio/ogg "access plus 1 month"
  ExpiresByType video/mp4 "access plus 1 month"
  ExpiresByType video/webm "access plus 1 month"
# htc files  (css3pie)
  ExpiresByType text/x-component "access plus 1 month"
# webfonts
  ExpiresByType font/truetype "access plus 1 month"
  ExpiresByType font/opentype "access plus 1 month"
  ExpiresByType application/x-font-woff "access plus 1 month"
  ExpiresByType image/svg+xml "access plus 1 month"
  ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
# css and javascript
  ExpiresByType text/css "access plus 1 week"
  ExpiresByType application/javascript "access plus 1 week"
  ExpiresByType text/javascript "access plus 1 week"

缓存控制:

  <IfModule mod_headers.c>
    <FilesMatch "\.(ico|pdf|flv|jpe?g|png|gif|swf|ogg)$">
      Header set Cache-Control "max-age=2592000, public"
      Header unset Last-Modified
      Header unset ETag
      FileETag None
    </FilesMatch>
    <FilesMatch "\.(css)$">
      Header set Cache-Control "max-age=604800, public"
    </FilesMatch>
    <FilesMatch "\.(js)$">
      Header set Cache-Control "max-age=604800, private"
    </FilesMatch>
    <FilesMatch "\.(xml|txt)$">
      Header set Cache-Control "max-age=216000, public, must-revalidate"
    </FilesMatch>
    <FilesMatch "\.(x?html?|php)$">
      Header set Cache-Control "max-age=1, private, must-revalidate"
    </FilesMatch>
    <FilesMatch "\.(eot|font.css|otf|ttc|ttf|woff)$">
        Header set Access-Control-Allow-Origin "*"
    </FilesMatch>
  </IfModule>
</IfModule>
### / CACHING ###

我能做些什么来解决它?

顺便说一句,我发现了这个:htaccess 'Header unset Last-Modified' caching issue 但看起来这家伙对图像没有问题

【问题讨论】:

    标签: .htaccess caching last-modified


    【解决方案1】:

    鉴于此警告:

    指定 Last-ModifiedETag 标头以启用缓存 验证以下资源

    我怀疑你的配置中的这些行是罪魁祸首:

    标头未设置Last-Modified

    标题未设置ETag

    FileETag

    您的配置正在删除用于缓存验证的标头信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 2017-08-26
      • 2020-04-25
      • 2014-04-12
      相关资源
      最近更新 更多