Configure a cache busting resource chain

This commit configures a resource chain with
`resources.chain.strategy.content.enabled`, enabling cache busting for
static resources based on the hash of their content.

A template helper (here a Groovy Closure) is added to the model given to
the view for appending hashes to static links such as:

    "/css/spring.css" -> "/css/spring-d35c4193cd32e7e44cda5737205c0c0e.css"

Fixes #321
This commit is contained in:
Brian Clozel
2016-12-01 12:07:47 +01:00
parent 9967ebc3ad
commit 4de86e1401
7 changed files with 37 additions and 13 deletions

View File

@@ -29,6 +29,7 @@ import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.AsyncConfigurerSupport
import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
import org.springframework.web.servlet.resource.ResourceUrlProvider
/**
* Initializr service application. Enables legacy STS support for older
@@ -47,8 +48,9 @@ class InitializrService {
@Bean
@SuppressWarnings("deprecation")
LegacyStsController legacyStsController(InitializrMetadataProvider metadataProvider,
ResourceUrlProvider resourceUrlProvider,
GroovyTemplate groovyTemplate) {
new LegacyStsController(metadataProvider, groovyTemplate)
new LegacyStsController(metadataProvider, resourceUrlProvider, groovyTemplate)
}
@Configuration

View File

@@ -13,6 +13,11 @@ spring:
jackson:
serialization:
write-dates-as-timestamps: false
resources:
chain:
strategy:
content:
enabled: true
initializr:
env: