• We are trusted partners of:
Development

Extending The Symfony Assetic Google Closure Filter

By December 5, 2013 No Comments

If you’ve ever used the Symfony framework, then you’ve likely used the Assetic Bundle, which uses the Assetic library to provide asset management tools. The bundle provides a wrapper for the Google Closure which compresses and optimizes javascript.

To dump js wp-content, you would usually run:

In the background, this runs the Google closure binary that goes through all the scripts declared in your templates. By default, Google closure is set to follow the ECMASscript3 Standard, which is fine for most scripts. However, you will occasionally run into scripts or third party libs that do not follow the standard and Google closure will fail to dump the wp-content due to parse errors / reserved words problems. The quick solution to this is to change the standard that Google closure checks for when compiling to ECMASscript5, but Assetic currently has no configuration option to allow this. There is at least 1 pull request that adds a language option to the assetic config, but at the time of this writing it has yet to be merged. So in order to change the standard, we have to take a slightly longer route.

First, let’s extend the Assetic Google closure filter:

Second, let’s make this class a service:

And last, use this filter in the templates instead of the default closure filter:

At this point, when running

google closure should no longer fail when dumping the js wp-content.

INNOBYTE

Author INNOBYTE

More posts by INNOBYTE

Leave a Reply