0

I'm developing a web application with Spring MVC & Hibernate and I deploy it in Apache Tomcat 8.

My users use Google Chrome to use my app normally but when I make a change in the CSS or JavaScript and I redeploy the changes into tomcat the users don't see the changes in their browser!

So I have to manually clean the cache in the Chrome.

How can I disable cache so I can make changes and my users see them instantly ?

piet.t
  • 11,035
  • 20
  • 40
  • 49
Youssef
  • 6,411
  • 18
  • 67
  • 115
  • See for example https://www.keycdn.com/blog/http-cache-headers/. You may want to make sure you choose appropriate caching properties for the production system though. – JimmyB Jan 19 '17 at 12:40
  • Possible duplicate of [How can I force clients to refresh JavaScript files?](http://stackoverflow.com/questions/32414/how-can-i-force-clients-to-refresh-javascript-files) – Leonid Vasilev Jan 23 '17 at 10:22

2 Answers2

2

You can just add a deploy version to your css file so this will reset cache from version to version. E.g. stylesheet.css?v=2.1.1.

Ruslan Shashkov
  • 285
  • 3
  • 7
1

You should try adding a version number or maybe a timestamp date change on the scripts / link rels of your css / js like so:

<head>

   <script type="text/javascript" src="js/file.js?#version_number"></script>
   <link rel ="stylesheet" href="css/file.css?#version_number" />

</head>
  • where version number is should be replaced by server side code

this forces the browser to reload the scripts each time, instead of using the stored cache version of the script / stylesheet