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


Cache some files, not the others

我有静态内容(.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 小时重新生成一次。

在 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>