手机网页调试·清除浏览器缓存的方法


  在手机里调试网页的时候,总是为清除缓存烦恼。特别是QQ浏览器。最后甚至有同学开发出了Android下一键清除清除各种浏览器缓存的APP,但需要root,且每次耗时不短。最后经过尝试,发现了一个方便、有效的方法。那就是利用HTTP的响应头,让浏览器不缓存资源,每次刷新页面的时候都从服务器获取。

 

NodeJS 中的实现方法

NodeJS中可以通过设置一下方法设置响应头

res.setHeader("CacheControl", 'no-store');

 

Apache配置方法:

在Apache配置文件(MAC下的路径是/etc/apache2/httpd.conf)中打开mod_headers.so模块。一般默认都是打开的。

 

找到这一行:

LoadModule expires_module libexec/apache2/mod_headers.so

去掉前面的井号。

在站点配置下增加以下内容:

Header set Cache-Control "no-store"

最终示例如下:

<VirtualHost *:80>
    DocumentRoot "/Users/tick/Projects/local"
    ServerName localhost
 Header set Cache-Control "no-store"     <Directory "/Users/tick/local">
        Options Indexes FollowSymLinks
        AllowOverride ALL
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Nginx配置方法:

理论同Apache,具体配置如下

server {
        listen       81;
        #server_name r.hitick.com;
        #index index.html index.htm index.php;
        root /alidata/www/r.hitick.com;
        location ~ .*\.(php|php5)?$
        {
                #fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi.conf;
        }
        location ~* \.(eot|ttf|woff)$ {
                add_header Access-Control-Allow-Origin *;
        }
        location ~ .*\.(js|css|gif|jpg|jpeg|png|bmp|swf|eot|svg|ttf|woff)?$
        {
 add_header Cache-Control no-store;
        }
        access_log  /alidata/log/nginx/access/r.hitick.com.log;
}

更多关于浏览器的缓存机制及HTTP头的相关内容。可以看这篇文章。还是比较详细的。

http://www.cnblogs.com/skylar/p/browser-http-caching.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM