Changes made in js file or views file or css file doesn't gets reflected for the user

拜拜、爱过 提交于 2019-12-13 07:59:49

问题


I have developed a single page web application with multiple views on it. For rendering these views ng-if has been used.

Each view has a separate controller. Many click functionality has been handled using Jquery. For backend, java has been used. The whole application has been developed in spring MVC and deployed on WebLogic.

The problem is whenever I make any changes to the views or the js file it won't get reflected after deploying the new WAR file without clearing cache and doing a hard refresh(ctrl+F5/R).

I got an answer to this question few minutes ago which was related to ServiceWorker and appCache but it no more in the answer list. Do anyone have any idea about this?

I need a permanent solution for this as I have more than 5000 users and I can't ask everyone to do this after each deployment.

I have tried to provide a version when I include it in an index.jsp like (filename.js?version=2.1). But this doesn't seem working for me. I haven't tested this on chrome or any other browser as only IE10, edge is available for me as well as the users.


回答1:


Adding a query at the end of JS file imported only work on a client side language.
If you are using a JSP file you can add this at the beginning of your file it will disable caching

<%
response.setHeader("Cache-Control","no-cache"); 
response.setHeader("Pragma","no-cache"); 
response.setDateHeader("Expires", -1);
%>

For IE you need to add these HTML tags :

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> 
<META HTTP-EQUIV="Expires" CONTENT="-1">

You can specify an expiration date for the file in response.setDateHeader("Expires", -1);
See this for more information



来源:https://stackoverflow.com/questions/56808398/changes-made-in-js-file-or-views-file-or-css-file-doesnt-gets-reflected-for-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!