-
Notifications
You must be signed in to change notification settings - Fork 97
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
Dependency aware asset digests #175
Conversation
Just here to mention that we've switched our propshaft to wlipa's fork and it indeed does solve the dependency aware digesting 👍 |
Apologies for the random drive-by here, but this PR solves a real organizational problem for my CSS with Propshaft and I'd love to see it (or something like it) land in a release. @brenogazzola and/or @dhh, I'm curious what you think of this PR? (Thanks @wlipa!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the submission!
Overall this looks good to me, but I've left some suggestions for a some things that should be cleaned up and I'd prefer a second opinion from @dhh or @brenogazzola before merging.
def dependency_tree | ||
Propshaft::DependencyTree.new(compilers: compilers) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason to have this exposed as a public method? I understand it makes the load_path
method more legible, but I suggest this is made private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No specific reason; that was done to copy the style of the rest of the methods.
def digest | ||
@digest ||= Digest::SHA1.hexdigest("#{content}#{version}").first(8) | ||
@digest ||= begin | ||
Propshaft.logger.warn("digest dependencies not ready for #{logical_path}") if digest_too_soon? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm missing something obvious, but in what scenario would an asset have dependencies but no dependency fingerprint? It's just not clear to me what should be done by users in response to this warning, so either failing more loudly (and clearly) or not warning at all seems like better options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should only happen if there was a bug in the dependency tree logic. Since digest bugs are insidious, I decided a warning was necessary, but going to the extent of failing a build for inadequate cache busting seemed a little much.
Replaced by #188. |
This PR adds dependency aware asset fingerprinting/digests to address the issue of stale assets remaining in the cache if an indirect dependency changes. It specifically affects css files with embedded url references, both to image assets and in @import statements. Js files use the import-map mechanism which avoids the need for any changes there.
The basic idea is to extract the dependencies using the css asset url compiler that updates them in the first place. This is done after the load_path assets_by_path method creates all the asset objects. A new DependencyTree class gets invoked to handle any assets with dependencies in an ordered fashion that will create stable digests that incorporate dependency fingerprint information.
Here is a walkthrough of the individual class changes.
Asset
Compiler
Compilers
CssAssetUrls
Assembly
LoadPath
DependencyTree
Fixes #123 and #90