如何让浏览器不缓存js与css文件
配置服务器响应头:
通过配置服务器响应头,如Cache-Control、Expires和ETag,可以控制浏览器对资源的缓存行为。
在Apache服务器上,可以在.htaccess文件中添加如下内容:
apache
<FilesMatch ".(js)$"> Header set Cache-Control "no-cache, no-store, must-revalidate" Header set Pragma "no-cache" Header set Expires 0 </FilesMatch>
nginx
location ~* \.(js)$ {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
}css同理