2

Spring Boot or Tomcat caches my static assets .js and .css files in development environment and I have to Build -> Build Project (in IntelliJ) every time to get the refreshed version.

I tried these application properties and they didn't work.

spring.resources.cache-period=0
spring.resources.chain.cache=false
spring.resources.chain.html-application-cache=false
spring.resources.chain.strategy.content.enabled=false
spring.resources.chain.strategy.content.paths=/**

I tried to have this bean to configure Tomcat and it didn't work as well:

@Bean
    public EmbeddedServletContainerFactory servletContainer() {
        TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory() {

            @Override
            protected void postProcessContext(Context context) {
                final int cacheSize = 0;
                StandardRoot standardRoot = new StandardRoot(context);
                standardRoot.setCachingAllowed(false);
                standardRoot.setCacheMaxSize(cacheSize);
                context.setResources(standardRoot);    
            }
        };
        return tomcatFactory;
    }

When changing js and css files I don't want to do Build Project every time, I can even use something like BrowserSync to apply changes automatically to the web page but for that I need Tomcat/Spring to serve static assets in dev environment without me clicking to Build Project.

The doc is not really helpful and according to the doc there is no way except clicking Build every single time changing a css or js file. http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-hotswapping

But I believe this should be something very simple and perfectly achievable isn't it.

Any ideas what should I try next?

Thanks

Seregwethrin
  • 1,319
  • 2
  • 13
  • 24

1 Answers1

3

This in no cache. Your source files (*.js and *.css) are copied when you build the project in a separate folder (eg target) and from there they are sent to the browser. Build Project button copied this files and then you see that they have changed.

You may enable Build project automatically option in IntelliJ or use other tool (eg bower) for copy files after changing.

Community
  • 1
  • 1
Nick
  • 3,691
  • 18
  • 36
  • Thank you very much, IntelliJ Idea registry settings worked!!! Should have thought about that target/ folder before... Cheers! – Seregwethrin Mar 27 '17 at 13:44