I have a main.js in thymeleaf template, each time I call it I want to add a version parameter so that it will not be cached and my latest changes will work.
<script src="/main.js?version=345345456"></script>
</body>
</html>
Since it's the layout behind all other templates, I don't want to pass a variable from controllers.
So I decided to add a bean method to my application class
@SpringBootApplication
public class NexusApplication {
@Bean
public double jsVersion(){
return Math.random();
}
}
Than I added:
<script th:src="@{/js/my-script.js(version=NexusApplication.jsVersion())}"></script>
Output is:
<script th:src="@{/main.js?(version=NexusApplication.jsVersion())}"></script>
What am I missing? How should I approach this issue in a better way?