手機網頁調試·清除瀏覽器緩存的方法


  在手機里調試網頁的時候,總是為清除緩存煩惱。特別是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