设置 HTTP 缓存过期时间,Google PageSpeed 推荐
我使用 Google 的 PageSpeed 在我的网站上运行了测试,它建议我“利用浏览器缓存”并提供以下资源:
http://code.google.com/speed/page-speed/docs/caching.html#LeverageBrowserCaching
此资源从未解释如何实际更改我的过期日期http 标头。我是否通过 .htaccess 执行此操作?我想将缓存设置得尽可能长(不违反 Google 最长一年的政策)。
任何有关推荐设置(针对自定义 php 驱动的社交网络社区)的建议将不胜感激。
I ran tests on my website using Google's PageSpeed and it recommends that I "Leverage browser caching" and provided the following resource:
http://code.google.com/speed/page-speed/docs/caching.html#LeverageBrowserCaching
This resource never explains how to actually change the expiration date of my http headers. Do I do this through .htaccess? I would like to set the caching for as long as possible (without violating Google's policy of a year max).
Any advice on recommended settings (for a custom php-driven social networking community) would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的根目录的 .htaccess 中:
并遵循:
这是我在管理的每个属性上使用的完全相同的代码,并为我(和 PageSpeed)提供了最令人满意的结果。人们可能会争论具体的规则,这就是为什么我说它满足我,但它肯定满足PageSpeed。
In your root's .htaccess:
And follow by:
This is the exact same code I use on every property I manage and offers me (and PageSpeed) the most satisfying results. One may argue on specific rules, that's why I said that it satisfies me, but it certainly satisfies PageSpeed.
可以使用 htaccess 和 php 来完成。通常,您不想强制缓存实际的 html,因为它是动态数据库驱动的内容(如果需要,可以使用
header()
php 函数来完成)。你想要缓存的是外部css & JavaScript 和图像文件。请参阅此处的 .htaccess 解决方案: http://www.askapache.com/ htaccess/apache-speed-expires.html
It can be done with both htaccess and php. Typically you wouldn't want to force caching the actual html since its dynamic database driven content (it can be done with the
header()
php function if needed). What you want to cache is external css & javascript, and image files.See here for an .htaccess solution: http://www.askapache.com/htaccess/apache-speed-expires.html