Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
Spring Boot or Tomcat cache static assets, have to re-build every time to refresh

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

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda