html里script标签src自动加上时间戳,降低缓存影响 |
您所在的位置:网站首页 › js后面加时间戳 › html里script标签src自动加上时间戳,降低缓存影响 |
为了强制加载,在文件名后加上类似于hash串的时间戳或者随机数。 找了很久大佬们的解决方案,感觉下面这个最好用。 document.write("");大佬还提供了个 (function(){ var randomh=Math.random(); var e = document.getElementsByTagName("script")[0]; var d = document.createElement("script"); d.src = "//site.com/js.js?x="+randomh+""; d.type = "text/javascript"; d.async = true; d.defer = true; e.parentNode.insertBefore(d,e); })(); (然而这个不知道如何加载多个js。。)缓存相关设置 强制不超过一天: Cache-Control: max-age=86400, must-revalidate 永远获取最新文件: Cache-Control: no-cache, must-revalidate
大佬↓: |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |