Incrase Your Symfony2 Web Application with YUI Jquery and CSS Compressor

1. Instal Java JDK in your environtment

 

2. Download the YUI Compressor JAR

The YUI Compressor is written in Java and distributed as a JAR. Download the JAR from the Yahoo! site and save it to app/Resources/java/yuicompressor.jar.
Unzip, go to build/ dir and extract yuicompressor-2.4.7.jar to put it in your app/Resources/java/ project dir. (In addition, you can rename yui file for yuicompressor.jar)

3 - Enable yui compression for prod environement

This is logical to add yui compressor in your config_prod.yml file and not for all environment (you should remove lines from config.yml).
So add theses lines in config_prod.yml:
assetic:
    debug: false
    filters:
        yui_js:
            jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
            apply_to: "\.js"
        yui_css:
            jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
            apply_to: "\.css"

4. Verify you prod controller file

Go to web/app.php, and set prod / false (false for no debug).
$kernel = new AppKernel('prod', false);

5. Clear cache

If you want to rebuild your CSS and JS (after update), never forget to clear cache in prod otherwise modifications will be ignored by yui compressor:
php app/console cache:clear --env=prod --no-debug

6 - Regenerate fixtures with compression

you can generate and compress your files !
php app/console assetic:dump --env=prod --no-debug -v
Note that -v show more details about the process of compression, you will be able to see if there is an error taht causes problems with yui compressor !
For example, the JS comment tag "/!" causes trouble with yui compressor, you should rename all "/!" for "/*" in your JS files.

7. Fixing Clear Cache Issue

because you had been clear cache, then you will have  problems on the path.
to overcome execute this command

rm -rf app/cache

And feel the different

 

SHARE ON:

Hello guys, I'm Tien Tran, a freelance web designer and Wordpress nerd. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae.

    Blogger Comment

0 komentar:

Posting Komentar