Skip to content

Commit

Permalink
Add cache headers for static resources with hashed name and icons/media
Browse files Browse the repository at this point in the history
  • Loading branch information
matthijsln authored and mprins committed Dec 24, 2024
1 parent c5b3021 commit 9f9f51e
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package org.tailormap.api.configuration.base;

import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
Expand Down Expand Up @@ -38,6 +39,13 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
.addResourceHandler("/version.json")
.addResourceLocations(resourceLocations.split(",", -1)[0])
.setCacheControl(CacheControl.noStore());
registry

Check warning on line 42 in src/main/java/org/tailormap/api/configuration/base/WebMvcConfig.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/base/WebMvcConfig.java#L42

Added line #L42 was not covered by tests
// Add cache headers for frontend bundle resources with hash in filename and fonts/images
.addResourceHandler("/*/*.js", "/*/*.css", "/*/*.map", "/*/media/**", "/*/icons/**")
.addResourceLocations(resourceLocations.split(",", -1)[0])
.setCacheControl(CacheControl.maxAge(7, TimeUnit.DAYS).mustRevalidate())
.resourceChain(true)
.addResolver(new EncodedResourceResolver());

Check warning on line 48 in src/main/java/org/tailormap/api/configuration/base/WebMvcConfig.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/tailormap/api/configuration/base/WebMvcConfig.java#L44-L48

Added lines #L44 - L48 were not covered by tests
registry
.addResourceHandler("/**")
.addResourceLocations(resourceLocations.split(",", -1)[0])
Expand Down

0 comments on commit 9f9f51e

Please sign in to comment.