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 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?