在Apache服务器上使用.htaccess实现缓存控制
好吧,我仍在尝试了解一些缓存内容,并且我已经浏览了一些可以在 Google 上找到的示例。我已将以下代码添加到我的 .htaccess 文件中:
### activate mod_expires
ExpiresActive On
### Expire .gif's 1 month from when they're accessed
ExpiresByType image/gif "access plus 3 months"
ExpiresByType image/png "access plus 3 months"
ExpiresByType image/jpg "access plus 3 months"
ExpiresByType text/javascript "access plus 3 months"
使用 Chrome 审核工具和 YSlow Firebug 工具,看起来这正在缓存我的一些图像/文件,但到目前为止还不是全部。我仍然有一个未缓存的文件列表(.jpg、.js 和 .css - 我知道我没有将 css 文件设置为缓存)。 Chrome 审核中的消息只是指出以下资源缺少缓存过期。未指定过期时间的资源可能不会被浏览器缓存:
一些未缓存的图像是背景图像,其他图像是 js 库的一部分,并且它们是通过 JS 调用的 - 可以吗会影响为什么他们不缓存?
抱歉,我无法提供代码链接 - 该网站仍处于保密状态,仅限客户查看。
提前致谢!
okay, I'm still trying to get my head around some of the caching stuff and I have gone through a couple of examples I could find on Google. I have added the following code to my .htaccess file:
### activate mod_expires
ExpiresActive On
### Expire .gif's 1 month from when they're accessed
ExpiresByType image/gif "access plus 3 months"
ExpiresByType image/png "access plus 3 months"
ExpiresByType image/jpg "access plus 3 months"
ExpiresByType text/javascript "access plus 3 months"
Using the Chrome audit tools and the YSlow Firebug tool, it looks like this is caching some of my images/files, but not by far all of them. I still have a list of files (.jpg, .js and .css - I know I've not set the css files to cache here) that aren't caching. The message in the Chrome audit simply states The following resources are missing a cache expiration. Resources that do not specify an expiration may not be cached by browsers:
some of the images that aren't caching are background images, others are part of a js gallery and they're being called via the JS - could that be affecting why they aren't caching?
Sorry I can't give a link to the code - the sites still under wraps and limited to client view only.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您写错了 MIME 类型:
It looks like you've written the MIME-types wrong: