Kiwwito

Code Snippets and More

Unify all our CSS and JS stuff into unique minified files improves significantly your application performance.

Thanks to the Assetic Symfony2 bundle you can do it on the fly.

First, download the YUI compressor, unzip it and move the "yuicompressor-*.jar" to the "app/Resources/java" folder.

Connect Assetic with the compressor (config.yml file):

assetic:
    filters:
        yui_css:
            jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
        yui_js:
            jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"

Now we can minify and unify our CSS and JS files. The way to do it is inserting into our base Twig layout (for example) the next code:

{% stylesheets filter='?yui_css' output='css/compiled-main.css'
    '@MyBundle/Resources/public/css/*'
%}

Assetic will compile all of the CSS files of our bundle into a minified and unified one.

In development environment the process will generate the file for every request. For production environment you have to generate the file manually through the next command:

php app/console assetic:dump --env=dev --no-debug

Recent comments

© 2014 Copyright by Keyvan Akbary