在Apache服务器上使用.htaccess实现缓存控制 [英] Implementing cache control using .htaccess on Apache server

查看:98
本文介绍了在Apache服务器上使用.htaccess实现缓存控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我仍在努力寻找一些缓存方面的知识,并且我列举了一些我可以在Google上找到的示例。我已将以下代码添加到我的.htaccess文件中:

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"

使用Chrome审核工具和YSlow Firebug工具,似乎正在缓存我的某些图像/文件,但到目前为止还不是全部。我仍然有未缓存的文件列表(.jpg,.js和.css-我知道我没有将css文件设置为在此处缓存)。 Chrome审核中的消息仅说明以下资源缺少缓存过期。未指定到期时间的资源可能不会被浏览器缓存:

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:

一些未缓存的图像是背景图像,其他图像是js画廊的一部分,并且通过JS调用它们-可能会影响为什么不进行缓存的原因吗?

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.

预先感谢!

推荐答案

看起来您写错了MIME类型:

It looks like you've written the MIME-types wrong:

# enable expirations
ExpiresActive On
ExpiresDefault "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/pjpeg "access plus 1 week"
ExpiresByType text/javascript "modification plus 1 week"
ExpiresByType application/javascript "modification plus 1 week"
ExpiresByType text/css "modification plus 1 week"

这篇关于在Apache服务器上使用.htaccess实现缓存控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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