[opencms-dev] Auto-Condense Javascript and CSS code - new opencms tag cms:minify

Michael Moossen m.moossen at alkacon.com
Mon Feb 16 11:52:01 CET 2009


Hi Christian!

It is in my (unofficial) schedule to implement something similar to this.

Nice to see that i am not the only one thinking in that direction, but 
since you normally (and if you are a good JS dev, always!) want to 
minify whole JS files, i think that your tag implementation is not the 
best (it also implies that all your JS files have to be JSP files 
preventing the usage of export points for them).

Right now it is planned to use a property and it will only (YUI) minify 
files with the set property when accessed online, but not offline for 
better debugging.

this will also help to clean up OpenCms VFS from those jquery packed and 
  unpacked versions...

-------
by the way, you can use the <cms:jquery /> tag with any JS file. (a more 
appropriate name for this tag would be cms:jsinc or even cms:htmlinc 
since you can also use it to include CSS files)

just copy your JS file (myfile.js) into
/system/workplace/resources/jquery/unpacked/
and the packed (or not, or minified, or smth else to be used online) 
version into
/system/workplace/resources/jquery/packed/

and you can include your js file using this piece of code:
<cms:jquery js='myfile' />
--------

an idea that just run through my mind is to extend the cms:jquery tag to 
something like:
<cms:jquery js='myfile' minify='true' />
or even
<cms:jquery js='myfile' minify='--nomunge
--disable-optimizations' />

may be this is an even better solution, so the control is on the 
template and not on the file itself, allowing to use in one template a 
minified version and in another a 'normal' version (but what for...)

any suggestion would be appreciated!

Kind regards,
Michael

-------------------

Alkacon Software GmbH  - The OpenCms Experts
http://www.alkacon.com - http://www.opencms.org


Christian Steinert wrote:
> Dear all,
> 
> inspired by the jQuery support in OpenCms, I have implemented a new tag 
> for the opencms taglib, called cms:minify.
> 
> The tag can automatically condense JavaScript and CSS code. The tag is 
> used by enclosing a block of CSS of JavaScript with it, for example:
> 
>     <cms:minify type="js">
>     function myFunc() {
>       myVar = 123;
>       alert( myVar );
>     }
>     </cms:jsminify>
> 
> The result in this case would be: "function myFunc(){a=123;alert(a)}"
> 
> The tag implementation together with instructions is available from: 
> http://www.berzinarchives.com/temp/opencms/cms-minify.1.0.zip
> 
> *@ALKACON*: I would very much like to see this code being added to the 
> regular opencms distribution. The implementation is one single Java 
> class the size and structure of which is very much comparable to other 
> classes in the opencms taglib. The code is documented and written to 
> work with Java 1.4. It's licensed under LGPL. The code uses the 
> excellent YUI compressor (BSD license) which has also been adopted by 
> the jQuery team. If you could rename the class and add it to a future 
> version of opencms, I then think this could give a boost to JavaScript 
> development with OpenCms.
> 
> 
> The tag is capable of detecting if it is in an offline project. In this 
> case, no compression will be done so that developers can still see their 
> code in full beauty at development time.
> 
> I would appreciate feedback.
> 
> Best Regards
> Christian
> 
> 
> ------------------------------------------------------------------------
> 
> 
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev



More information about the opencms-dev mailing list