Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache busting issue when configured ContentVersionStrategy + CssLinkResourceTransformer #26382

Open
didiez opened this issue Jan 13, 2021 · 5 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement
Milestone

Comments

@didiez
Copy link

didiez commented Jan 13, 2021

When configuring ContentVersionStrategy we are experiencing a problem when a resource referenced in a css file is modified (url with md5 hash changed) but the css file itself remains exactly the same (same md5 hash).
We are not getting the last version as the application is rewritting the resource with the same hash (i.e: style-8736f7fc00b943645acfcde4d1456233.css) but the actual content is different (different hashes in the rewritten urls inside de css file).

Are we doing something wrong?
Is there a way to compute de md5 hash (ContentVersionStrategy) after content of the css has been transformed by the CssLinkResourceTransformer?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 13, 2021
@didiez
Copy link
Author

didiez commented Jan 13, 2021

Here's a simple application to reproduce the issue https://github.com/didiez/spring-resources-versioning-issue

@bclozel
Copy link
Member

bclozel commented Jan 13, 2021

I think that's a limitation of the current design. When resolving paths with the the resource chain, the ContentVersionStrategy is only looking at the actual resource content and not involving the resource transformer chain. Any transformer impacting the content of the resource is not changing the content and the hash of the resource remains the same.

We should take a look at this limitation and see if we can fix this without breaking existing contracts.

As a side note, HTTP caching config and the resolver chain strategies should be enabled in production-specific profiles and left out of the dev profile. I know this is probably done on purpose in this sample, I just wanted to point that out in case this issue is bothering you while working on your app.

Thanks!

@bclozel bclozel added status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 13, 2021
@bclozel bclozel added this to the 5.x Backlog milestone Jan 13, 2021
@didiez
Copy link
Author

didiez commented Jan 13, 2021

Thanks for the quick response :)

Yes, http caching is enabled by default to simplify the sample. We have no issues while developing as these properties are only defined for production. Thanks for pointing it out, though.

@rstoyanchev
Copy link
Contributor

From recollection I think we discussed this at some point. The option I recall is to configure the resource chain and provide a Cache instance to use. This instance can then be used to invalidate the cache. It's a crude mechanism but one option at least.

@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jul 26, 2021
@ealouie
Copy link

ealouie commented Mar 1, 2024

Has there been any more consideration of a fix for this issue? My coworkers and I ran into this issue with one of our css files we were caching that is importing from fontawesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants