assetic-bundle
assetic-bundle copied to clipboard
Added assetic:list command to output list of asset files and their md5 hash
This PR introduces a new command, assetic:list
that produces a list of all asset files and optionally an md5 hash from dumped output or source file contents:
$ app/console assetic:list --md5=file
429ec0da456d16a44ec609153322fa94 css/reset.css
71622ad6e734e307fb22437261e4b39a css/480.css
To output full file paths, use --paths
:
429ec0da456d16a44ec609153322fa94 /var/www/symfony2-project/app/../web/css/reset.css
71622ad6e734e307fb22437261e4b39a /var/www/symfony2-project/app/../web/css/480.css
Use Case: Cache Busting
As there is not yet reliable cache busting solution (see for example https://github.com/symfony/AsseticBundle/pull/119 ), we do use the output of assetic:list
to generate a master hash of all asset files:
$ app/console --env=prod assetic:list --md5=file | md5sum
If the master hash changes between deployments (meaning a source file content has changed, a new file is added, a file is renamed or removed), we'll do actual assetic:dump
and upload new dumped files to CDN to an address prefixed with the master hash. The master hash is set to framework.templating.assets_base_urls
configuration variable in config.yml
.
--md5=file
does not directly see changes which don't alter the sources but the output itself (filters, asset grouping etc). If it's required, one can use assetic:list --md5=dump
that generates a hash from asset's dumped output.
@vmattila Just a quick question/proposal. Could this feature be used for listing all assets for documentation purposes? I was just recently requested to provide a list of all 3rd party code in our application (yes, crazy, I know :) and I thought it'd be so cool if assetic would help me with listing all javascript assets. It seems to me this PR gets quite close to what I'd need for that kind of use case too.
Morjes @TomiS ! I think this command could be easily used for that purpose - but I would keep the command only as a simple helper to extract the file list. What came to my mind would be adding -print0
or similar argument to support better passing the file list to xargs
and other commands...
@vmattila Sounds good to me. So :+1: for this PR from here (after the CS fixes, of course :)
Did some code cleaning per @Baachi 's comments. I left the proposed ´--print0´ argument away at this point, we can work with that later.
Nice. +1
+1
+1, very useful
+1
Updated the PR with previously discussed --print0
option to help operation with xargs
or similar command.
+1