[opencms-dev] Auto-Condense Javascript and CSS code - new opencms tag cms:minify
Christian Steinert
christian_steinert at web.de
Mon Feb 16 12:30:55 CET 2009
Dear Michael,
thanks for your reply - great that you have something like this in mind,
too.
Concerning the ideas that you have:
> 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...
>
I like the idea of using a property to control this. On the one hand
this gets rid of the requirement of requiring the CSS/JS stuff to be in
JSP files, which I agree not everybody will like. (I use JSP anyway to
include things together, but this is just me).
> -------
> 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' />
>
I see - good to know.
> 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...)
>
I like the idea of giving control to the template.
What I would really not like though, is if the tag would generate a URL
that starts with /system/. I know that this would be the easiest way to
implement something like that, but it means that the /system folder
needs to be publically available when serving stuff. Since I use static
export a lot, I really don't like that idea of making a /system/ folder
available without being able to fix the URL.
Would there be a way to trigger minification by just appending some URL
parameter to the original css/jsp URL? If the resultant URL that are
generated by the tag would work similar to how image resizing works,
then this would be ideal in my opinion and I would prefer this solution
over using a file system property to control minification.
Another thing that I would like is, if the new functionality would not
require files to be located at a fixed location. I would prefer to be
able to reference files in the same way like it's possible with
<cms:link />. Using a new tag name (rather than extending cms:jquery)
seems preferable to me to minimize confusion.
My suggestion would be to have a tag that can be used like this:
<cms:resource js="/path/to/file.js" options="--nomunge
--disable-optimizations" force="true" />
and that could generate a URL similar to that:
/path/to/file.js?__minify=js:/path/to/file.js;options:--nomunge+--disable-optimizations
I don't know how feasible the parameter-based URL processing part of
this would be. If this does not require changing the opencms core (I am
afraid it does, though), I would be willing to try and implement
something like that.
Best Regards
Christian
More information about the opencms-dev
mailing list