Changes made in js file or views file or css file

2019-09-19 13:12发布

问题:

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