控制缓存过期 [英] Controlling Cache Expirations

查看:244
本文介绍了控制缓存过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行通过谷歌网站管理员工具PageSpeed​​分析我的网页后,它向我报告说没有我的资源被缓存。下面是code。在我的.htaccess文件直接从H5BP拍摄。我是正确的假设之下到期设置正确和什么是错在我的实现还是我必须设置明确的到期日为每个文件名,而不是泛泛?

 #------------------------------------- ---------------------------------
#Expires头(为了更好的高速缓存控制)
#------------------------------------------------- ---------------------

#这是pretty的遥远的未来的Expires头。
#他们认为你操控了基于文件名的清除缓存版本
#此外,考虑到过时的代理可能miscache
#www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/

#如果你不使用的文件名的版本,降低CSS和JS喜欢的东西
#进入加1周。

< IfModule mod_expires.c>
  ExpiresActive上

#也许是更好的白名单到期规则?也许。
  ExpiresDefault进入加1月

在FF 3.6#cache.appcache需要重新申请(感谢雷米〜介绍HTML5)
  ExpiresByType文本/缓存清单的访问以及0秒

#您的文档HTML
  ExpiresByType text / html的连接以及0秒

# 数据
  ExpiresByType应用/ JSON的连接以及0秒
  ExpiresByType应用程序/ xml的访问以及0秒
  ExpiresByType文本/ xml的访问以及0秒

# 饲料
  ExpiresByType应用程序/原子+ XML进入加1小时的
  ExpiresByType应用程序/ RSS + XML进入加1小时的

#网站图标(不能重​​命名)
  ExpiresByType图像/ X-图标进入加1周

#媒体:图像,视频,音频
  ExpiresByType音频/ OGG进入加1月
  ExpiresByType图像/ GIF进入加1月
  ExpiresByType为image / jpeg进入加1月
  ExpiresByType图像/ PNG进入加1月
  ExpiresByType视频/ MP4进入加1月
  ExpiresByType视频/ OGG进入加1月
  ExpiresByType视频/ W​​EBM进入加1月

#HTC文件(css3pie)
  ExpiresByType文/ x分量进入加1月

#Webfonts
  ExpiresByType应用程序/ vnd.ms-fontobject进入加1月
  ExpiresByType应用程序/ x-字体TTF进入加1月
  ExpiresByType应用程序/ x-字体WOFF进入加1月
  ExpiresByType字型/ OpenType字体进入加1月
  ExpiresByType图像/ SVG + XML进入加1月

#CSS和JavaScript
  ExpiresByType应用程序/ JavaScript的进入加1年
  ExpiresByType文本/ CSS进入加1年

< / IfModule>
 

解决方案

这看起来很不错。

要么你没有安装mod_expires模块(在一百万1不)或一些其他的.htaccess或httpd.conf中指令禁用这些其他地方。请使用pagespeed工具来​​抓取你的文件实际发送的报头,并粘贴。

After running my webpage through Google Webmaster Tools' PageSpeed analyzer, it has reported to me that none of my resources are being cached. Below is the code in my .htaccess file taken directly from H5BP. Am I correct in assuming the below expirations are set correctly and something is wrong in my implementation or do I have to set explicit expirations for each file name and not broad generalizations?

# ----------------------------------------------------------------------
# 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>

解决方案

That looks good.

Either you don't have the mod_expires module installed (1 in a million don't) or some other .htaccess or httpd.conf directive is disabling these somewhere else. Please use the pagespeed tool to grab the actual headers sent by your files, and paste.

这篇关于控制缓存过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆