添加版本号解决浏览器缓存
方法1
<script> var projectVersion = "1.0"; createScript("/static/index.js"); function createScript(url){ var script = document.createElement('script'); //创建script标签 script.type = "text/javascript"; script.src = url+"?v="+projectVersion ; document.getElementsByTagName('head')[0].appendChild(script); } </script>
方法2
<script> var projectVersion = "1.0"; document.write("<script src='/static/index.js?v="+projectVersion +"'><script>"); document.write("<link rel='stylesheet' href='/static/index.css?v="+projectVersion+"'>"); </script>
其他
在jsp页面上添加
<link rel="stylesheet" href="/static/index.css?v=<%=session.getAttribute("VERSION")%>"> <script src="/static/index.js?v=<%=session.getAttribute("VERSION")%>"></script>