DEV Community

Discussion on: Caching SPA static assets in Grails

Collapse
 
tylervz profile image
Tyler VanZanten

Thank you! My Grails 4.0.1 application is now having my static assets cached by the browser.

I'm having trouble getting the WebMvcConfigurer to work properly though so that certain resources are not cached. I created a class named StaticAssetsResolverConfig (in a package under /src/main/groovy) that implements WebMvcConfigurer and has the org.springframework.stereotype.Component annotation.

gist.github.com/tylervz/bdb2c07a34...

First, is there a different place I need to put my class in order for it to get recognized by Grails and get executed? I needed to register it as a bean in resources.groovy (as you noted was an option) for it run. The good news is that I know StaticAssetsResolverConfig is running, so it's not too big of a deal. In case anyone else is wondering, this is how I defined the bean in resources.groovy:

staticAssetsResolverConfig(StaticAssetsResolverConfig)

Second, the resources I want to not have cached still have a Cache-Control: max-age=100 response header when requested. I'm using the following path pattern parameters in my call to registry.addResourceHandler():

'/static/ui5/com/**/*.xml', '/static/ui5/com/**/*.js'

Any tips on how to get this working would be greatly appreciated!