【问题标题】:Cache some files, not the others缓存一些文件,而不是其他文件
【发布时间】:2016-05-11 10:02:57
【问题描述】:

我的页面包含静态内容 (.jpg) 和服务器端缓存内容 (.jpg)。

<body>

// Static content, "never change"
<img src="my_static_image.jpg">

// This image change every 6 hours, its name will not change.
<img src="changing_image.jpg">

<body>

我想仅优化加载和重新加载更改的内容,而不是其余内容。 在我的情况下,changeing_image.jpg 保持相同的名称,但在服务器端每 6 小时重新生成一次。

【问题讨论】:

  • 如果我想将所有 jpeg 缓存 6 小时,请提供此答案。我的问题是缓存一些 jpeg 6 小时,例如其他 15 天。

标签: php apache .htaccess caching browser-cache


【解决方案1】:

发现于http://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching.html#Apache_htaccess_caching_code

<FilesMatch "/static/"> <-- this is regex, you can match by filename rather than by extention
    Header set Cache-Control "max-age=29030400, public" <-- longer
</FilesMatch>
<FilesMatch "/changing/"> <-- this is regex, you can match by filename rather than by extention
    Header set Cache-Control "max-age=21600, public" <--6 hours in seconds
</FilesMatch>

【讨论】:

  • 是的,但是我的同类型文件(.jpg)呢。有些必须缓存 6 小时,有些必须缓存(例如 15 天)。
猜你喜欢
  • 2013-12-03
  • 2016-08-01
  • 2013-01-26
  • 1970-01-01
  • 2022-06-28
  • 2022-09-30
  • 2023-03-23
  • 2021-07-01
  • 1970-01-01
相关资源
最近更新 更多