Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Symfony 2 Assetic development comfortable

I'm looking for ways to make Symfony 2 Assetic 1.0.2 development easier. I use Assetic for dumping/publishing my assets.

Currently I keep running this command in the background:

php app/console assetic:dump --watch

It helps a lot, every change I make to JS or CSS files will automatically get dumped to the public directory where the resources are fetched from by the browser.

However, I have issues with this:

  1. If I add a new CSS/JS file, for some reason it does not get dumped. I need to stop the watch, clear the cache and initiate the watch again.

  2. It is kind of slow, eats 5%-20% CPU time constantly.

Is there an alternative to development with Assetic? I already tried the approach of serving the resources through a controller (use_controller: true for Assetic), but it was even slower (because let's face the fact, PHP is not for serving static data).

like image 602
Tower Avatar asked May 25 '12 07:05

Tower


3 Answers

For me, this is the fastest way to develop with Assetic I could find. I tried and I tried to find a better workflow to enhance speed of asset generation, but found none.

There is some work in the master branch of Symfony2 on a ResourceWatcher component which could possibly helps on this issue by:

  1. Speeding up the watching process by relying on native resource watcher like inotify
  2. Fixing problem when resources are added/removed so they are dumped correctly.

You can watch progress on the component in this PR.

Hope someone will provide some tricks to speed up development with assetic or a completely different workflow.

Regards,
Matt

like image 100
Matt Avatar answered Nov 18 '22 00:11

Matt


For slowness, you can run with --no-debug and --forks=4. Install Spork dependency through composer, and run app/console assetic:dump --no-debug --forks=4.

If you have more cores add more forks. If you want to keep core(s) free lower the number. Not sure why it isn’t 4 times faster - doubtless it is not too intelligent about assigning different assetic jobs to different cores - but it’s a start.

Some things I just tried briefly:

time app/console assetic:dump

real    1m53.511s
user    0m52.874s
sys     0m4.989s

time app/console assetic:dump --forks=4

real    1m14.272s
user    1m12.716s
sys     0m5.752s

time app/console assetic:dump --forks=4 --no-debug

real    1m9.569s
user    1m6.948s
sys     0m5.844s

I'm not sure that this will help with --watch, as --watch consumes an entire core on it's own, because while (true) in PHP.

like image 3
sennett Avatar answered Nov 17 '22 23:11

sennett


İn developpement use this:

php app/console assets:install web --symlink
like image 1
RaKoDev Avatar answered Nov 17 '22 22:11

RaKoDev