使用.htaccess進行瀏覽器圖片檔案快取,_PHP教程

來源:互聯網
上載者:User

使用.htaccess進行瀏覽器圖片檔案快取,


對於圖片類網站,每次開啟頁面都要重新下載圖片,慢不說,還非常浪費流量。這時就需要用到緩衝,強制瀏覽器緩衝圖片檔案

快取檔案,提問網站訪問數度,減少流量消耗,現提供2中緩衝代碼

開啟.htaccess檔案,寫入下面代碼

方法一:統一緩衝時間長度

Header set Cache-Control "max-age=2592000"

方法二:按不同檔案類型緩衝時間長度

ExpiresActive OnExpiresByType image/jpg "access 1 year"ExpiresByType image/jpeg "access 1 year"ExpiresByType image/gif "access 1 year"ExpiresByType image/png "access 1 year"ExpiresByType text/css "access 1 month"ExpiresByType text/html "access 1 month"ExpiresByType application/pdf "access 1 month"ExpiresByType text/x-javascript "access 1 month"ExpiresByType application/x-shockwave-flash "access 1 month"ExpiresByType image/x-icon "access 1 year"ExpiresDefault "access 1 month" #預設檔案快取時間長度,慎用

注意:

ExpiresDefault "access 1 month" ,預設檔案快取時間長度,慎用,否則你的有些方法將失效,比如記錄瀏覽量,必須F5重新整理頁面才可以

擴充閱讀:

如何建立.htaccess檔案?

下載.htaccess檔案

原文地址:http://cssteach.com/show-20-113.html

http://www.bkjia.com/PHPjc/1138634.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1138634.htmlTechArticle使用.htaccess進行瀏覽器圖片檔案快取, 對於圖片類網站,每次開啟頁面都要重新下載圖片,慢不說,還非常浪費流量。這時就需要用到緩衝...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.