I'm facing the fallowing problem with my webapp: every time I have to redeploy it (AWS), the page does not load correctly the first time because (I believe) the local cache has js
and css
files corresponding to the previously deploy. I'm using Angular backed up by Java and serving with Spring Boot.
When I foce a re-download (Ctrl + R, e.g.), everything works fine. In a attempt to fix this I added the following meta to my index.html:
<!--Setting the content to "0" tells the browsers to always load the page from the web server.--> <meta http-equiv="cache-control" content="max-age=0"/> <meta http-equiv="cache-control" content="no-cache"/> <meta http-equiv="expires" content="0"/> <meta http-equiv="expires" content="0"/> <meta http-equiv="pragma" content="no-cache"/>
Which apparently did not work. What can I do?
3 Answers
Answers 1
Maybe you can cheat this behaviour by adding a query to your files, somethink like :
<script src="myscript.js?build=mybuildversion"></script> <link href="mystyles.css?build=mybuildversion" rel="stylesheet">
Answers 2
You do not need to instruct the browser not to clear the cache for your index.html file. Rather its the CSS files which are being cache. However its not a recommended practice to clear the cache for static resources like images or css files. Rather these files should be cached for long periods to save bandwidth. If you want to force the browser to get a latest version of your static resources you need to make use of the Spring VersionResourceResolver strategy. https://dzone.com/articles/2-step-resource-versioning-with-spring-mvc or http://www.slideshare.net/rstoya05/resource-handling-spring-framework-41
Answers 3
I agree with @Rogerio Soares - your minified scripts should contain a unique identifier for each iteration they go through, whether it be in the filename or in the querystring that accompanies the path/url. This can be taken care of in the grunt/gulp build process.
0 comments:
Post a Comment