2013-11-21 61 views

回答

44

一般是使用主機上的.htaccess文件進行理解。這裏是剪切和粘貼從HTTP cache headers with .htaccess

<IfModule mod_headers.c> 
# WEEK 
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$"> 
    Header set Cache-Control "max-age=604800, public" 
</FilesMatch> 
</IfModule> 

如果從PHP外殼提供的材料,你可以使用PHP創建在這種情況下,你會提到這裏概述14.9節的Cache-Control http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

的HTTP protocal頭爲例
<?php 
/* This file is a wrapper, */ 

header('Cache-Control: max-age=604800'); 
/* now get and send images */ 
?> 

我認爲.htaccess更容易兩種方法。

+1

我發現這個.htaccess腳本非常有用https://github.com/h5bp/server-configs-apache/tree/master/dist – drooh

相關問題