Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 07b3d2f

Browse filesBrowse files
Sgoettschkesweaverryan
authored andcommitted
Adding UglifyCss and changing some wording
1 parent 520f468 commit 07b3d2f
Copy full SHA for 07b3d2f

File tree

Expand file treeCollapse file tree

1 file changed

+72
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+72
-6
lines changed

‎cookbook/assetic/uglifyjs.rst

Copy file name to clipboardExpand all lines: cookbook/assetic/uglifyjs.rst
+72-6Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
.. index::
22
single: Assetic; UglifyJs
33

4-
How to Minify JavaScripts with UglifyJs
5-
=======================================
4+
How to Minify CSS/JS Files (using UglifyJs and UglifyCss)
5+
=========================================================
66

77
`UglifyJs`_ is a javascript parser/compressor/beautifier toolkit. It can be used
88
to combine and minify javascript assets so they need less HTTP requests and makes
9-
the website load faster.
9+
the website load faster. `UglifyCss`_ is a css compressor/beautifier much like
10+
`UglifyJs`.
11+
12+
In this cookbook, the installation, configuration and usage of `UglifyJs` is shown
13+
in detail. `UglifyCss` works pretty much the same way and is only talked about briefly.
1014

1115
Install UglifyJs
1216
----------------
@@ -123,13 +127,75 @@ your assets are a part of the view layer, this work is done in your templates:
123127
With the addition of the ``uglifyjs`` filter to the asset tags above, you should
124128
now see minified JavaScripts coming over the wire much faster.
125129

130+
Install, configure and use UglifyCss
131+
------------------------------------
132+
133+
The usage of `UglifyCss` works the same way as `UglifyJs`. First, make sure
134+
the node package is installed:
135+
136+
.. code-block:: bash
137+
138+
$ npm install -g uglifycss
139+
140+
Next, add the configuration for this filter:
141+
142+
.. configuration-block::
143+
144+
.. code-block:: yaml
145+
146+
# app/config/config.yml
147+
assetic:
148+
filters:
149+
uglifycss:
150+
bin: /usr/local/bin/uglifycss
151+
152+
.. code-block:: xml
153+
154+
<!-- app/config/config.xml -->
155+
<assetic:config>
156+
<assetic:filter
157+
name="uglifycss"
158+
bin="/usr/local/bin/uglifycss" />
159+
</assetic:config>
160+
161+
.. code-block:: php
162+
163+
// app/config/config.php
164+
$container->loadFromExtension('assetic', array(
165+
'filters' => array(
166+
'uglifycss' => array(
167+
'bin' => '/usr/local/bin/uglifycss',
168+
),
169+
),
170+
));
171+
172+
To use the filter for your css files, make sure to use the assetics helper in
173+
your template:
174+
175+
.. configuration-block::
176+
177+
.. code-block:: html+jinja
178+
179+
{% javascripts '@AcmeFooBundle/Resources/public/css/*' filter='uglifycss' %}
180+
<link rel="stylesheet" href="{{ asset_url }}" />
181+
{% endjavascripts %}
182+
183+
.. code-block:: html+php
184+
185+
<?php foreach ($view['assetic']->javascripts(
186+
array('@AcmeFooBundle/Resources/public/css/*'),
187+
array('uglifycss')
188+
) as $url): ?>
189+
<link rel="stylesheet" href="<?php echo $view->escape($url) ?>" />
190+
<?php endforeach; ?>
191+
126192
Disable Minification in Debug Mode
127193
----------------------------------
128194

129195
Minified JavaScripts are very difficult to read, let alone
130-
debug. Because of this, Assetic lets you disable a certain filter when your
196+
debug. Because of this, Assetics lets you disable a certain filter when your
131197
application is in debug mode. You can do this by prefixing the filter name
132-
in your template with a question mark: ``?``. This tells Assetic to only
198+
in your template with a question mark: ``?``. This tells Assetics to only
133199
apply this filter when debug mode is off.
134200

135201
.. configuration-block::
@@ -149,7 +215,6 @@ apply this filter when debug mode is off.
149215
<script src="<?php echo $view->escape($url) ?>"></script>
150216
<?php endforeach; ?>
151217
152-
153218
.. tip::
154219

155220
Instead of adding the filter to the asset tags, you can also globally
@@ -161,4 +226,5 @@ apply this filter when debug mode is off.
161226

162227

163228
.. _`UglifyJs`: https://github.com/mishoo/UglifyJS
229+
.. _`UglifyCss`: https://github.com/fmarcia/UglifyCSS
164230
.. _`install node.js`: http://nodejs.org/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.