dounang1974 2013-07-18 20:45
浏览 143

.htaccess - 如何清除浏览器缓存?

I had some problems with browser caching. When css, js, image files change the content but not the name, we must send to browser to download the new one and discard cached files.

Just pressing F5 or something like this the new files are not being updated.

There is a way to force browser forget the cache and download the new version of files?

  • 写回答

1条回答 默认 最新

  • dsnpjz6907 2013-07-19 01:44
    关注

    Some people with this "issue"

    This and this pages gave me an idea and I want to share it. :). My directory structure is this:

    website/
       |- libs/
           |- css/
           |- js/
           |- imgs/
       |- system/
       |- site/
       |- .htacces
       |- index.php
    

    so, we can use the .htacces file to "fool" the browser like this:

    RewriteRule ^libs\.v[0-9]{1,}(.*) libs/$1
    RewriteRule ^(.*)\.v[0-9]{1,}\.css$ $1.css
    

    And, on htmlfiles use this:

    <link rel="stylesheet" type="text/css" media="all" href="path/to/libs/css/style.v2.css" />
    <script type="text/javascript" src="path/to/libs/js/javascripts.v1.js"></script>
    <img src="path/to/libs/imgs/logo.v5.png" alt="Logo" />
    

    or

    <link rel="stylesheet" type="text/css" media="all" href="path/to/libs.v1/css/style.css" />
    <script type="text/javascript" src="path/to/libs.v1/js/javascripts.js"></script>
    <img src="path/to/libs.v1/imgs/logo.png" alt="Logo" />
    

    This is working fine for me.. whem I change something on a file I just add or change the number after .v like: .v1, .v2

    Reason: this trick make the browser see "http://www.mydomain.com/libs/css/style.v1.css" and than.. the cache/browser will believe that is a new file.. ;)

    I hope to help someone.. any suggestions will be Welcome

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!