I recently wrote about the assets:install command, but there’s a more interesting way to handle your assets: Assetic.
You can add the Assetic bundle to your project with the following composer command:
composer require symfony/assetic-bundle
P.S. this command offers more options but this is not the place to talk about composer.
This bundle offers advanced assets management features, like minifying or compiling assets and optimizing images. This is done through filters.
One of the key feature of Assetic is that the “real” assets used by your frontend are dynamically generated, i.e. they do not normally exist anywhere on the disc.
Generating assets dynamically can be quite slow, especially when you have many filters; so it is only enabled by default on the DEV environment.
On PROD, the app expects to find real files on the disc.
This is when you use assetic:dump.
It will search for all assets handled by Assetic, generate them, and save them as real files.
Once again, you have to do this if you want to see latest changes on your PROD environment.
Basically, it boils down to three twig tags:
For more information about all the available options and filters, you can read the official documentation at http://symfony.com/doc/current/cookbook/assetic/asset_management.html
Now you see why you sometimes may find yourself using assets:install and sometimes the assetic:dump.
Of course it’s probably simpler to choose just one method to include assets in layouts, but I don’t see much harm in using both: just be sure you and your team mates know about this!