I need some tips on how to work with assets in Symfony 2. For example, do we have to always perform the assets:update every time an image is added ? I know Assetic take care of the management on css and javascript files but what about images? What would be the best practice for the front-end development with Symfony 2 ? How do you guys setup your css, images and js files in your app to make it easy to develop, deploy and change ?
-
Is `assets:update` a real command? I've not found it mentioned anywhere else, and can't find it in the Symfony/Assetic codebase. If it does exist, I'd be interested to know more about it. – Sam Jan 16 '14 at 12:01
-
Related: http://stackoverflow.com/questions/12123069/how-to-properly-change-what-composer-or-symfony2-does-after-running-composer-up – Kzqai May 19 '15 at 16:08
3 Answers
Regarding images, if you added it into your public folder, I think there's no need to perform assets:update
However, if you add the image within the resources folders of a bundle, you might have to, depending on your OS and which options you used when called assets:install
If you're using an OS which supports symlinks (linux, OS X, and I guess all OS but Windows), you can install the assets calling (I don't exactly remember the call, the important thing here is the symlink option):
php app/console assets:install web --symlink
This way, instead of having a copy of each bundle's resources, you'll have a symlink, so there should be no need to update. If you have an OS which doesn't support symlinks, I think you'll have to keep updating or reinstalling assets (in fact, I always used assets:install
, I didn't knew there was an update option :P).
Regarding the set up, I usually put all css, js, images and any public resources inside a bundle if it is used only within the bundle, and place it onto the public folder if it's used by many bundles, or I plan to use it in other bundles.

- 2,899
- 18
- 11
-
1Also, if you’re using Composer to update your vendor packages, don’t forget to set the `"extra": { "symfony-assets-install": "symlink" }` in your composer.json file ([see docs](http://symfony.com/doc/current/book/installation.html#updating-vendors)). – Geert Nov 11 '14 at 09:42
-
1The `symlink` also work on Windows when you are running cmd (or git bash) under Administrator mode. :) because Assetic works with http://php.net/manual/en/function.symlink.php which is supported on Windows. – Athlan Jul 31 '15 at 10:33
As of Symfony 2.7 this will generate relative symlinks in web
directory:
php app/console assets:install web --symlink --relative
In composer.json add:
"extra": {
"symfony-assets-install": "relative"
}
This will also generate relative symlinks on composer update
.

- 3,378
- 1
- 22
- 28
-
1Since composer.json is committed, and thus used during the install on a production environment, I'm not sure you want this in your composer.json directly. – Kzqai May 19 '15 at 16:08
Here is cool think about --symlink.You can configure(config) one time and use forever.If you want more http://www.w3docs.com/snippets/symfony/how-to-keep-symlinks-in-web-bundles-after-composer-update.html

- 2,809
- 26
- 30