-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Asset] Versionize assets according to a Manifest #19418
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
Conversation
*/ | ||
public function __construct($manifest) | ||
{ | ||
if (!is_array($manifest)) { |
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.
Why not simply __construct(array $manifest)
?
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.
much better
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.
You're right, fixed it.
I have something similar in a WIP (outside the core for now, to experiment with it before being restricted by the Symfony release schedule and its BC rules). However, in my case, I'm using a mapping Your proposal has a big drawback: it is not compatible with |
Not being compatible with
The only drawback I see with the name of the file not being altered across versions is with CDNs that would not support query string parameters. I don't have much experience with CDNs myself but a quick google search shows that both CloudFront and Akamai support query string parameters, so this might not be an issue.
I'm already using this strategy at regularjack/frontend-bundle. I'm looking into implementing your alternative (using a query string parameter) too. Any chance you can link your WIP here? |
@regularjack my WIP is currently only on my computer. I haven't pushed the code yet
From a quick search, MaxCDN and Cloudflare support it as well |
Closing for the reasons explained by @stof @regularjack Can you create an issue so that we keep track of the feature request? Thanks. |
Overview
Add the ability for the Asset component to version assets according to a Manifest. A manifest is simply a map of paths to their versioned selves, for example:
This is achieved by a
ManifestVersionStrategy
class whose constructor takes an array representing the manifest:Motivation
To optimize client-side caching, an asset's URL should only change when its contents change. A simple way to achieve this is to append a hash of the file's content to the name of the file, as part of the build process.
Many frontend build tools do this and at the same time generate a manifest that maps the file's original name to its versioned name.
Supporting this use case would make it easy to "hook" frontend build tools with the Asset component.
A starting point
This PR is deliberately simple because it's not the concern of the Asset component to produce the manifest or even to parse it. However, having the Asset component include a
ManifestVersionStrategy
would pave the way for improved support further up the stack (framework-bundle? symfony-standard?).If this PR is accepted and/or if its usefulness is acknowleged I'm willing to further contribute "up the stack" to better support this use case.