dongzhong2008 2015-11-07 04:40
浏览 62

如何缓存图像一年,但html / php只有24小时

I'm new here so sorry if this is in the wrong category or something like that. Now getting to my problem. I have a website: www.windowstaan.pe.hu which also opens on a mobile app so in order to make it load fast I have enabled caching in .htaccess and here's its code:

## 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 ##

Now what happens here is that any page I load in the browser can also be loaded offline which is what I wanted, but if I make any changes to the html then I'm not sure how its going to update here.

My html files are saved as index.php, PHP because they have some PHP code in them mainly include header, footer and a small mysql line.

Now what I want is for this homepage and every other html/php page to reload every day.

Please tell me what I need to do in .htaccess to set it like that.

I have tried setting html / css to 1 day there but that is not working perfectly as my app still loads the old cache. (My app is just a browser of windowsphone 8.1, IE11 probably.)

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • duanke9540 2015-11-07 05:28
    关注

    The browser caching will base on the resource URL.

    When you want to force browser to reload the new resource, you just change the URL by adding a version string.

    For example, current image URL:

    http://static.adzerk.net/Advertisers/af217662e49a4cbda030feae88418cdd.png
    

    You can change to:

    http://static.adzerk.net/Advertisers/af217662e49a4cbda030feae88418cdd.png?v=1
    

    The version number can be controlled in your PHP code.

    Version control number can be read/write from a text file in case you do not use DB.

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题