[[Dashboard | << Back to Dashboard ]] | << Projects Viewer {| align="right" | __TOC__ |} = JSMin Compressor For ColdBox Applications = This is a plugin that interfaces with our own flavor of [http://www.crockford.com/javascript/jsmin.html 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. {| cellpadding=?5?, class="tablelisting" ! '''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: #getMyPlugin("JSMin").minify('includes/js/myscripts.js,includes/js/jquery.js')# #getMyPlugin("JSMin").minify('includes/css/site.css,includes/css/boxes.css')# 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!