缓存一些文件,而不是其他文件

时间:2016-02-02 14:32:42

标签: php apache .htaccess caching browser-cache

我的页面包含静态内容(.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>

我想优化加载和刷新仅更改的内容,而不是其他内容。 在我的例子中,changing_image.jpg保持相同的名称,但在服务方每6小时重新生成一次。

1 个答案:

答案 0 :(得分:0)

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>