YUICompressor CFC v0.1 Released

If you are looking for ways to minify, optimize, and compress your CSS and Javascript with ColdFusion, this is an all-in-one solution based on the YUI Compressor Java library.

It’s simple but powerful.

The project and code: YUICompressor CFC @ RIAForge

There is some sample code included with the download package.


project: YUICompressor CFC
author: Tom de Manincor
version: 0.1.1
date: 2/18/2010

-overview-
This CFC allows you to use the YUI Compressor Java library.

"The YUI Compressor is a JavaScript compressor which, in addition to removing
comments and white-spaces, obfuscates local variables using the smallest
possible variable name. This obfuscation is safe, even when using constructs
such as 'eval' or 'with' (although the compression is not optimal is those
cases) Compared to jsmin, the average savings is around 20%.
The YUI Compressor is also able to safely compress CSS files. The decision
on which compressor is being used is made on the file extension (js or css)"

This CFC adds some more flexibility. It accepts an input string or a file, as long as its valid JS or CSS.
You can also choose to return the compressed results back as a string or a file.

It is using the YUI components for both CSS and JS.
For more information on the YUI library visit:
http://developer.yahoo.com/yui/compressor/

-requirements-
ColdFusion 7 or Higher
JavaLoader (optional)
YUI Compressor Java Library (version 2.4.2 included)

-usage-
The constructor (init method) is required if using inheritance (ClassLoaderAdapter).

Since this is dependent upon the YUI Java library,
I have integrated a ClassLoaderAdapter that allows you to toggle between JavaLoader
or the CF native ClassLoader that will use libraries found in your CF class path.
Remember, if you are not going to use JavaLoader then make sure you put the yuicompressor-2.4.2.jar in your CF class path.
If this is the approach you choose you also have the option to discard the ClassLoaderAdapter.
Instead of using the YUICompressor.cfc and the ClassLoaderAdapter.cfc, rename and use the included YUICompressor_noinheritance.cfc.

-note-
Do not use the additional libraries that are bundled with the base jar. String Index out of range errors may occur.

-credits-
Joe Roberts

0.1 -INITIAL RELEASE- 2/18/2010
-JS and CSS compression supported
-auto detect input type
-allow input files or string
-output to file or string

Leave a Reply

Your email address will not be published. Required fields are marked *