Projects:JSMin-Compressor
<< Back to Dashboard | << Projects Viewer
|
JSMin Compressor For ColdBox Applications
This is a plugin that interfaces with our own flavor of JSMin to minify css and js files. It can also compress several files of the same type into a single include in order to save even more bandwidth and file space. Of course it is recommended that you only compress into a single file either js or css assets.
Download
You can download the JSMin compressor from ForgeBox: http://www.coldbox.org/index.cfm/forgebox/view/JSMin-Compressor
Configuration Settings
In order for JSMin plugin to work, you must declare the following settings in your ColdBox configuration.
| Setting | Type | Required | Default | Description |
|---|---|---|---|---|
| jsmin_enable | Boolean | false | true | flag to enable disable the packaging process |
| jsmin_cacheLocation | String | true | --- | The relative file location where cached minified js/css files will be stored, this location will be expanded. ex: includes/cache |
Here is an example of the settings:
settings = {
// JSMIN
jsmin_enable = true,
jsmin_cachelocation = "includes/cache",
};
Important: Please make sure that the directory for the cache location is writable and exists. If not, you will receive errors.
Usage
minifiy()
minify(assets:string) : html script or link tags
The main method of operation is minify(). You pass to it a list of assets to compress, but they have to be of the same type: js or css. Do not alternate or weird results will happen. This method returns a script or link include that you would output on your layouts, let's see an example:
<head> #getMyPlugin("JSMin").minify('includes/js/myscripts.js','includes/js/jquery.js')# #getMyPlugin("JSMin").minify('includes/css/site.css','includes/css/boxes.css')# </head>
As you can see from the example above, you can easily render the minified version of all the assets. This plugin will minify each asset and if more than 1 is declared, then it will build a concatenated version of the js or css assets and cache them. When you inspect the source you will see that it includes 1 javascript file and 1 css file. These files are from the disk cache and are named with a unique id.
minifyToHead
minifyToHead(assets:string) : void
This method basically sends the html links and script tags to the head section using cfhtmlhead. You can use this method when calling JSMin via handlers or plugins or any other location than layouts.
So now go out and have fun minifiying with ColdBox!
Adam Euans said
at 09:14:03 AM 24-Dec-2009
Adam Euans said
at 09:19:11 AM 24-Dec-2009
Luis Majano said
at 12:36:08 PM 25-Dec-2009
George Murphy said
at 06:08:46 AM 01-Aug-2010
SideBar
User Login
Comments (