[英]How to cache images for a year but html / php for only 24 hours
我是新來的,如果這是錯誤的類別或類似內容,請對不起。 現在解決我的問題。 我有一個網站:www.windowstaan.pe.hu,該網站也在移動應用程序上打開,因此為了使其快速加載,我在.htaccess
啟用了緩存,這是其代碼:
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType 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 day"
ExpiresByType text/html "access 1 day"
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"
</IfModule>
## EXPIRES CACHING ##
現在,這里發生的是,我在瀏覽器中加載的任何頁面也都可以脫機加載,這正是我想要的,但是如果我對html進行了任何更改,那么我不確定在這里如何對其進行更新。
我的html文件保存為index.php
,因為它們中包含一些PHP代碼,這些代碼主要包括頁眉,頁腳和一小段mysql行。
現在,我想要的是此主頁以及每天重新加載的所有其他html / php頁面。
請告訴我我需要在.htaccess
進行哪些設置。
我曾嘗試將html / css設置為1天,但由於我的應用仍加載舊緩存,因此無法正常運行。 (我的應用程序可能只是Windows Phone 8.1,IE11的瀏覽器。)
提前致謝。
瀏覽器緩存將基於資源URL。
當您要強制瀏覽器重新加載新資源時,只需添加版本字符串即可更改URL。
例如,當前圖像URL:
http://static.adzerk.net/Advertisers/af217662e49a4cbda030feae88418cdd.png
您可以更改為:
http://static.adzerk.net/Advertisers/af217662e49a4cbda030feae88418cdd.png?v=1
可以在您的PHP代碼中控制版本號。
如果不使用DB,則可以從文本文件中讀取/寫入版本控制編號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.