简体   繁体   中英

Cache busting mechanism for Java/SpringMVC/Maven project

A little background about the app that I'm working in: Spring MVC, Java EE Web application, Maven.

Basically, what I'm looking for is a mechanism to refresh all JS and CSS files upon each deployment of our application. As it stands right now, the application is referencing static files (eg "js/app.js"). Every time there is a change to this file, after redeploying locally, we get a 304 when the browser goes to download it (file has not been modified). My questions are:

1) Would it be better to serve these files up again upon redeployment of application and use maybe the application version as a cache busting mechanism (eg "js/v1.0.0/app.js"). This can maybe be done via a servlet filter.

2) Since the project is a maven dynamic web project, is there some sort of plugin that does this sort of thing. I was looking at wro4j to see if it can do this, but from the very little I read about it, it's mostly used to handle minification of these JS and CSS, which is something also very useful.

Which is the right approach? Thanks in advance

I don't know about the "right" approach but the most common solution is to use versioning of the static files eg app.js will become app-14gd54646rfw3.js the number is usually a MD5 of the content thus it will only change when the file changes

with spring you achieve it by built-in mechanism as described at the following link http://www.baeldung.com/cachable-static-assets-with-spring-mvc

if you want to use Maven plugin with concatenating and minifying abilities you can use a gulp or grunt tasks as build tools

you can find more information here https://css-tricks.com/strategies-for-cache-busting-css/

您应该将版本添加到静态资源或禁用浏览器中的缓存

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM