assetic-bundle icon indicating copy to clipboard operation
assetic-bundle copied to clipboard

Added assetic:list command to output list of asset files and their md5 hash

Open vmattila opened this issue 11 years ago • 11 comments

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 avatar Jul 28 '13 14:07 vmattila

@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.

TomiS avatar Aug 13 '13 12:08 TomiS

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 avatar Aug 13 '13 12:08 vmattila

@vmattila Sounds good to me. So :+1: for this PR from here (after the CS fixes, of course :)

TomiS avatar Aug 13 '13 13:08 TomiS

Did some code cleaning per @Baachi 's comments. I left the proposed ´--print0´ argument away at this point, we can work with that later.

vmattila avatar Sep 01 '13 09:09 vmattila

Nice. +1

nurikabe avatar Sep 17 '13 11:09 nurikabe

+1

rejinka avatar Sep 24 '13 08:09 rejinka

+1, very useful

yellow1912 avatar Oct 18 '13 04:10 yellow1912

+1

tomiford avatar Oct 18 '13 21:10 tomiford

1

wwotoole avatar Oct 23 '13 02:10 wwotoole

Updated the PR with previously discussed --print0 option to help operation with xargs or similar command.

vmattila avatar Feb 08 '14 14:02 vmattila

+1

bigfoot90 avatar Feb 16 '14 00:02 bigfoot90