Cache busting not working
See original GitHub issueFollowing https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc-static-content it should be enough to add
spring.resources.chain.enabled=true
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**
to my application.properties
in order to enable the cache busting / fingerprinting of my static assets.
Here’s an example thymeleaf doc head:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title th:text="#{page.title}"></title>
<link th:href="@{/css/main.css}" rel="stylesheet" media="screen"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
However, the output is still /css/main.css
without any version.
Spring Boot v2.2.6.RELEASE
id ‘org.springframework.boot’ version ‘2.2.6.RELEASE’
id ‘io.spring.dependency-management’ version ‘1.0.9.RELEASE’
implementation ‘org.springframework.boot:spring-boot-starter-thymeleaf’
Also running in the IDEA / running the build jar makes no difference.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Cache Busting Not Working? Google Chrome? - Stack Overflow
Chrome seems to be pretty enthusiastic about caching. I've pushed out a few updated js files that required multiple hard refreshes (Ctrl + ......
Read more >Cache busting stopped working - WordPress.org
In the latest update cache busting is broken. Function *_build_single_hash_url* says: // $qs_hash is from src, same as $filename, redundant.
Read more >Cache busting in Angular. The problem - Medium
The problem: The cache does not automatically clear on every angular update. Let's first define what the cache does.
Read more >Cache Busting Explained - StackPath Help
Cache busting is the process of uploading a new file to replace an existing file that is already cached. This is useful because...
Read more >Cache Busting - Advanced Ads
If you send out a feed or promote your content on external sites, Cache busting is not working, and will fall back not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ultraq kudos to you for you efforts - I was finally able to nail the issue down to
lazy-initialization
.Once I
spring.main.lazy-initialization=true
cache-busting is gone. This seems like a bug to me for the docs say that bean stuff is delayed until an actual HTTP request hits the bean. But it has nothing to do with thymeleaf. I’ll open an issue in spring.Thanks!
I was able to get it working by taking the example app downloadable from https://spring.io/guides/gs/serving-web-content/, matching the versions of the dependencies you listed, then adding an
application.properties
file with the config values in your post, adding<link rel="stylesheet" th:href="@{/css/test.css}"/>
to thegreeting.html
file, and adding an empty CSS file in thesrc/main/resources/static/css
directory. Result:One thing I noticed: if there was no file at the target path (like after I got it working I deleted
test.css
), then Spring Boot couldn’t fingerprint my file and I’d get the plain/css/test.css
in the HTML from the server. So it might be good to double check paths to resources are correct as that seems to be a requirement for getting it working too.But the fingerprinting is definitely working with Thymeleaf, so if there are more configuration issues then it might be worth asking over on the Spring Boot GitHub or on StackOverflow with the spring-boot tag.