http - 控制缓存中文件的过期时间

标签 http caching header http-headers

我想知道您是否可以帮助我,我正在尝试为我网站中的某些文件的缓存设置过期日期,您是否可以给我一些如何做到这一点的提示?我已经能够找到一些关于如何更改整个文件类型的东西,但不是特定文件。这可能吗?

ExpiresActive On                  # enable expirations
ExpiresByType image/gif A2592000  # expire GIF images after a month
                                 #  in the client's cache
ExpiresByType text/html M604800   # HTML documents are good for a
                                 #  week from the time they were
                                 #  changed, period

最佳答案

这可以帮助您: http://viralpatel.net/blogs/2009/06/21-very-useful-htaccess-tips-tricks.html

查看提示 #6:“使用 .htaccess 实现缓存方案”。 我认为您可以从这里提出基于特定文件的处理。

<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified
</FilesMatch>

<FilesMatch ".(html|htm|xml|txt|xsl)$"> Header set Cache-Control "max-age=7200, must-revalidate" </FilesMatch>

<FilesMatch ".(js|css)$"> Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT" </FilesMatch>

关于http - 控制缓存中文件的过期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2114414/

相关文章:

PHP 简单缓存

caching - CUDA:什么时候使用共享内存,什么时候依靠L1缓存?

c++ - 为什么要将整个 header 内容放在保护 token 中?

MySQL:将列值转换为带有总计的标题

asp.net-mvc-3 - 将自定义 html 添加到 WebGrid 中的 header

http - 在不修改请求状态的情况下读取 http.Request 的正文?

http - 是否可以在 GAE 中接受没有内容长度的帖子?

iphone - 发送带有图像的 http post 请求时出错

java - 内容编码是否设置为 UTF-8 无效?

asp.net - 缓存大量对象的方法(ASP.NET 缓存与静态对象以及单独缓存对象与字典)