调试中除了在URL上加时间戳外,如何避免js、css被返回304状态?_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:48:51
Original
2040 people have browsed it

在本地开发环境(nginx)中,经常遇到这样的情况:调试js时浏览器总是不载入已修改的js内容,而直接吐出了上次缓存的代码。

 

我曾经做过以下尝试:

ctrl+F5

ctrl+F5+F5+F5+F5+F5+F5

service nginx restart

service nginx stop ... service nginx start

service php-fpm restart

service php-fpm stop ... service php-fpm start

reboot

在nginx配置里加expires -1;

在nginx配置里加add_header Cache-Control 'no-store';

均告失败。

 

在谷歌浏览器的调试模式下发现所有js文件全部是清一水儿的304 Not Modified。再去搜索引擎里查找解决办法,又清一水儿的答案:在js的url后面加时间戳:

/static/js/common.js -> /static/js/common.js?2015.03.04

但在开发调试中,不能每次调试都要改一下url吧?

 

功夫不负有心人,终于偶然在一家外国网站看到一个网友也遇到了这个问题,并且自问自答:

在nginx配置中增加

if_modified_since off;

add_header Last-Modified "";

 

重启nginx后,大功告成!

ps:如果还不行,记得先随便修改一下js文件的内容,并保存,再刷新即可。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!