dongshi9526 2016-12-08 09:08
浏览 141

如何使用.htaccess避免浏览器缓存CSS,JS和图像文件?

RewriteCond %{REQUEST_URI} ^/[images|css|js]/
RewriteRule ^/(.*)$ /$1?ver=2 [L]

Now am using this code. But its not working.

  • 写回答

2条回答 默认 最新

  • dongwei2983 2016-12-08 09:14
    关注

    Htaccess solution :

    You might want to use mod_headers functions Cache-Control and Expires, for the file types you want the browser to not cache :

    <filesMatch "\.(js|css|jpg|jpeg|png|gif)$">
    FileETag None
    <ifModule mod_headers.c>
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
    </ifModule>
    </filesMatch>
    

    Source

    PHP solution :

    You could also load each resource with a different timestamp each time your page is shown :

     <script type="text/javascript" src="myfile.js?time=<?php echo mktime(); ?>" />
     <link rel="stylesheet" media="screen" href="/myfile.css?time=<?php echo mktime(); ?>">
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题