-1

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.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • Possible duplicate of [how to provide versioning for css, js, jsp files](https://stackoverflow.com/questions/56818898/how-to-provide-versioning-for-css-js-jsp-files) – georgeawg Jun 29 '19 at 18:23
  • See "Invalidating and updating cached responses" https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching. Changing the file name is suggested there. Appending a random query string has worked for me in the past although you say this doesn't work. – Alan Hay Jul 01 '19 at 14:39

1 Answers1

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

Toothgip
  • 469
  • 6
  • 14
  • as you suggested it will disable caching but it will slow down the application as each time it will download the included files. Isn't it? – Praveen Kumar Jun 28 '19 at 14:22
  • Yes, but in setDateHeader you can specify a date of expiration. See https://docs.oracle.com/cd/E13158_01/alui/wci/docs103/devguide/tsk_pagelets_settingcaching_httpexpires.html for more information – Toothgip Jun 28 '19 at 14:27