Skip to content

Instantly share code, notes, and snippets.

Last active May 21, 2020 21:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Grails 4 configuration class for specifying static files that should not be cached
package com.hypercision.attproto.assets
import groovy.transform.CompileStatic
import org.springframework.stereotype.Component
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
class StaticAssetsResolverConfig implements WebMvcConfigurer { // WebMvcConfigurerAdapter for Grails 3.x
// Copied from the GrailsWebMvcConfigurer
// -
private static final String[] RESOURCE_LOCATIONS = [
"/", "classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/"
void addResourceHandlers(ResourceHandlerRegistry registry) {
// Want to match all of our application JavaScript and XML i.e.
// /src/main/resources/public/ui5/com/hypercision/attproto/Device/crud/list/List.controller.js
// When I use these patterns, the matched files are still being cached:
// '/static/ui5/com/**/*.xml', '/static/ui5/com/**/*.js'
// When I use this pattern, then files named List.controller.js are not cached:
// '/static/**/List.controller.js'
// When I use this pattern, the matched files are returning 404 status from the server:
registry.addResourceHandler('/static/ui5/com/**/*.xml', '/static/ui5/com/**/*.js') // ant matcher pattern
.setCachePeriod(0) // <-- no-cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment