doujiao2443 2010-12-18 19:18
浏览 192
已采纳

避免浏览器缓存更新

After reading this question I was wondering if I could prevent browser cache by appending my application version to the uri at the top of my index file.... like so:

$revision = getRevision();
if($_GET['v'] != $revision){
  header('Location: index.php?v=' . $revision);
}

Will this work?

The end goal is to reset the entire cache - JavaScript, CSS, images - when i push an update in, perferably, a nice little one liner

  • 写回答

2条回答 默认 最新

  • douhuan1648 2010-12-18 19:43
    关注

    If the page itself is cached, yes. You will also have to do it to any images/css/js or external files that are available via a URL on your site (assuming you are passing cache headers so they are, in fact, cached) and are contained in that page because the browser caches all available URLs and they aren't grouped together by what page called them - they are all independent. So if index.php contains an IMG then the IMG will still be called from cache even if you change index.php?v=1234. You'd have to add ?v=1234 on the image as well in order to re-fetch both the page and the image.

    The version system is typically something you append to all cacheable URLs that can be modified (like css and js) but want to be invalidated as soon as it is updated. You typically append ?VERSION to the URL or ?version=VERSION to all URLs in whatever fashion makes sense (making sure not to break URL parameters).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3