The YUI Compressor is no longer maintained by Yahoo. That's why you are strongly advised to avoid using YUI utilities unless strictly necessary. Read How to Minify CSS/JS Files (Using UglifyJS and UglifyCSS) for a modern and up-to-date alternative.
Download the YUI Compressor JAR¶
The YUI Compressor is written in Java and distributed as a JAR. Download the JAR
from the Yahoo! website and save it to
Configure the YUI Filters¶
Windows users need to remember to update config to proper Java location.
In Windows7 x64 bit by default it's
C:\Program Files (x86)\Java\jre6\bin\java.exe.
You now have access to two new Assetic filters in your application:
yui_js. These will use the YUI Compressor to minify
Minify your Assets¶
You have YUI Compressor configured now, but nothing is going to happen until you apply one of these filters to an asset. Since your assets are a part of the view layer, this work is done in your templates:
The above example assumes that you have a bundle called AppBundle and your
Resources/public/js directory under your
files no matter where they are.
With the addition of the
yui_js filter to the asset tags above, you should
can be repeated to minify your stylesheets.
Disable Minification in Debug Mode¶
debug. Because of this, Assetic lets you disable a certain filter when your
application is in debug mode. You can do this by prefixing the filter name
in your template with a question mark:
?. This tells Assetic to only
apply this filter when debug mode is off.
Instead of adding the filter to the asset tags, you can also globally
enable it by adding the
apply_to attribute to the filter configuration, for
example in the
apply_to: "\.js$". To only have the filter
applied in production, add this to the
config_prod file rather than the
common config file. For details on applying filters by file extension,
see Filtering Based on a File Extension.
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License .