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秒的有效期。