Description
I would like the Asset component to be able to version assets according to a Manifest. A manifest is simply a map of paths to their versioned selves, for example:
/images/foo.png => /images/foo-123abc.png
/css/bar.css => /css/bar-789xyz.css
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.
This can be achieved by a ManifestVersionStrategy
class whose constructor takes an array representing the manifest:
$manifest = array(
'/images/foo.png' => '/images/foo-123abc.png',
'/css/bar.css' => '/css/bar-789xyz.css',
);
$versionStrategy = new ManifestVersionStrategy($manifest);
// Returns '/images/foo-123abc.png'
$versionStrategy->applyVersion('/images/foo.png');
// Returns '/css/bar-789xyz.css'
$versionStrategy->applyVersion('/css/bar.css');
// Returns '789xyz'
$versionStrategy->getVersion('/images/foo.png');
This is a followup to PR #19418