Assetic automatic cache busting without query?
Question
I couldn't find much information on this.
I want to compile all css (and js indeed) files into something like this:
css/all-c498dsfbc.css
Right now I'm only able to get these:
css/all.css
css/c498dsfbc.css
css/all.css?v=123
The first one sucks, because it has no cache busting at all.
The second one generates a hash which could be used for cache busting, but for some reason it doesn't change when I change something in my .css files and then run again this:
$ php app/console assetic:dump --env=prod --no-debug
The third one sucks too because I'm required to change the version manually, as explained here: http://symfony.com/doc/current/reference/configuration/framework.html#ref-framework-assets-version. Also, I don't think using queries for this is a good idea (I think some browsers or CDN might not like that). It would be much better if the filename was changed: 'all-c498dsfbc.css'. This is how it's done in Rails if I remember correctly.
Any thoughts?
EDIT
Seem like this feature is missing, I can't believe it: https://github.com/kriswallsmith/assetic/pull/190
Solution
In our project to ensure that new content won't be cached by Varnish for each deployment we manually change version - and assets pick that one. I think, it is a common practice. But in our case - it saves it in folder such as web/version-1.2.3/css/all.css
.
Our config for framework
section:
templating:
engines: ['twig']
assets_version: %release_version%
assets_version_format: "version-%%2$s/%%1$s"
OTHER TIPS
I know this is an old thread but it is at the top of Google so I thought it worth the update:
You can now do this with assetic using the cache buster worker. However the 2.3.0 assetic bundle does not have the config for it so you need to manually enable it for now. This can be done will the following service definition:
#config.yml or a service.yml
#...
services:
assetic.worker.cache_buster:
class: Assetic\Factory\Worker\CacheBustingWorker
public: false
arguments:
lazy_manager: @assetic.asset_manager
tags:
worker_factory: { name: assetic.factory_worker }
This work around is from the pull request for the configuration of the cache buster worker: https://github.com/symfony/AsseticBundle/pull/119/files