Apache
用戶設備在Apache上緩存靜態內容時,配置如下:
<FilesMatch “.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$”>
Header set Cache-Control “max-age=604800, public”
</FilesMatch>
<FilesMatch “.(xml|txt)$”>
Header set Cache-Control “max-age=18000, public, must-revalidate”
</FilesMatch>
<FilesMatch “.(html|htm|php)$”>
Header set Cache-Control “max-age=3600, must-revalidate”
</FilesMatch>
上面的內容需要被配置在項目的.htaccess文件中。
Nginx
用戶設備在Nginx上緩存靜態內容時,配置如下:
Location ~ .*\.(jpg|png|css|js)$ {
Expires 7d;
}
以上的內容需要配置到項目的conf文件中,寶塔爲例:/www/server/panel/vhost/nginx/www.aiqiyi.com.conf
設置好上面的配置信息後,響應頭信息內容如下圖所示:
從上圖中可以清晰的看到,js文件是從cache中加載的,並且設置了七天或者604800秒的有效期。