In your main template you probably should have assetic to manage your assets. In the production environment you would like to dump this to static files.
To dump the assets you run the following command:
This will generate a file like root/web/js/53ad2515.js. This is awesome. This file should be cached with very generous expiration date. This file should also be handled by your CDN.
The solution suggested by the Symfony2 docs is that you use assets_version. You should update that config every time you made some changes in the assets. But that gives a new version of all the assets, including images, and forces my users to download them again.
I would like my users to download some assets every time I deploy. I start with specifying an output in my main template.
Since Assetic needs to precompile the assets it needs to know what the available values version may have. We just need one version.
I use the parameter %git_commit%. I want this parameter to change every time I deploy. Create a new file called app/config/version.yml and make sure to include it in app/config/config.yml.
You just have to do one more thing before this will work. You have to “give” that variable value to Assetic. You have to override the AsseticBundle\DefaultValueSupplier with a class of your own.
If you run assetic:dump now you will get a file called root/web/js/script.sha1.js. The tricky part now is to automatically change version.yml when you deploy. I make sure my deployment script executes the following bash script.