How to selectively disable spring boot cache (manifest.appcache)

From this question, he shows that spring security manages the cache for spring boot. The spring boot documentation shows how to set the cache for resources using:

spring.resources.cache-period= # cache timeouts in headers sent to browser

cache-periodgreat for all predefined static locations for loading spring (ie /css**, /js/**, /images/**), but I also generated manifest.appcachefor offline download my static assets and because of all the above spring protection / loading sends cache cache headers with manifest.appcache

"method": "GET",
"path": "/manifest.appcache",
"response": {
    "X-Application-Context": "application:local,flyway,oracle,kerberos:8080",
    "Expires": "Tue, 06 Oct 2015 16:59:39 GMT",
    "Cache-Control": "max-age=31556926, must-revalidate",
    "status": "304"
}

, manifest.appcache. IE Chrome, , " " appcache, , FF, , , , appcache , , - .

EDIT: WebMvcAutoConfiguration, , , , 1 spring .

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if (!this.resourceProperties.isAddMappings()) {
            logger.debug("Default resource handling disabled");
            return;
        }

        Integer cachePeriod = this.resourceProperties.getCachePeriod();
        if (!registry.hasMappingForPattern("/webjars/**")) {
            registry.addResourceHandler("/webjars/**")
                    .addResourceLocations("classpath:/META-INF/resources/webjars/")
                    .setCachePeriod(cachePeriod);
        }
        if (!registry.hasMappingForPattern("/**")) {
            registry.addResourceHandler("/**")
                    .addResourceLocations(RESOURCE_LOCATIONS)
                    .setCachePeriod(cachePeriod);
        }
    }
+4
3

Q A!

: (Chrome, Safari, IE), (FF) , .

Spring Boot . , , Spring Boot, .

:

+2

, IE, "max-age = 1, must-revalidate" ,

spring.resources.cache-period=1

HTTP, appcache. , ( - 0 - , ), appcache.

- , (js/css/html) appcache.

+3

( 2016) - . application.properties:

# Enable HTML5 application cache manifest rewriting.
spring.resources.chain.html-application-cache=true

# Enable the Spring Resource Handling chain. Disabled by default unless at least one strategy has been enabled.
spring.resources.chain.enabled=true
# Enable the content Version Strategy.
spring.resources.chain.strategy.content.enabled=true 
# Comma-separated list of patterns to apply to the Version Strategy.
spring.resources.chain.strategy.content.paths=/** 

# Locations of static resources.
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/

. Spring , (If-Modiffied-Since ) appcache.

In addition, if there are reasons not to use the content version for some resources, you can use the alternative FixedVersion strategy and set the version explicitly in your configuration:

#Enable the fixed Version Strategy.
spring.resources.chain.strategy.fixed.enabled=false 
# Comma-separated list of patterns to apply to the Version Strategy.
spring.resources.chain.strategy.fixed.paths= 
# Version string to use for the Version Strategy.
spring.resources.chain.strategy.fixed.version= 

PS Don't forget Spring Security: it rewrites cache headers and disables caching.

More in docs

+2
source

All Articles