cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lars Huttar <>
Subject Re: using Cocoon for on-the-fly minification?
Date Wed, 09 Sep 2009 11:26:26 GMT
Thanks for this reply.
Since writing my original post, I tried subclassing ResourceReader to
create MinifyingReader, but I just don't have the Java & Cocoon
knowledge to make it work. Also it seemed like YUI compressor is
designed mainly to be command-line driven rather than driven by a Java API.
I did not know about the modified Rhino code base issue. Maybe the
answer is to use JSMin or Packer as you suggested in your July 2008

Regarding efficiency...

> The basic argument against this was that it is more efficient to do
> this at build time.

Yes I'm sure that's the best decision for many projects, but certainly
for some projects the better decision may be to pursue development-time
efficiency rather than run-time efficiency. Especially since your js/css
files should be cached the vast majority of the time, so the minifier
would be called rarely.
And we are using Cocoon 2.1.*, so Maven is not really an option.
Currently we have no build process as such, so adding one (such as using
Ant) just for this would be a significant step up in complexity.

You also pointed out that if your js is generated (as in JSON data?),
you can't minify it at build time, although that case doesn't apply to us.

My point is that there is room for different project teams to come to
different (and reasonable, intelligent) conclusions regarding whether to
minify at runtime; so having the freedom to choose is worthwhile.

You could make a similar argument for gzipping content... although the
issues are a little different. But most agree that gzipping is fine to
do at runtime, even though it would be more runtime-efficient to gzip at
build time, for static files.

Anyway, the above is just my advocacy saying there is a legitimate use
case: it would be a boost to our production app to have run-time, cached
minification of css and js. We could do the minification at "build time"
 (either manage it by hand, or create a process), but run-time
minification when the cache is unpopulated would be plenty fast enough,
and would guarantee that we don't serve stale minified js.

If you're willing to finish off the MinifyingReader (and it's compatible
with Cocoon 2.1.11), we would be happy customers.


On 9/8/2009 5:11 PM, Kamal Bhatt wrote:
> Hi.
> What you are talking about is a reader.
> I created a cocoon 2.2  reader which minified JS scripts (using jsmin)
> but the view on the dev mailing list was debate if there was a real need
> for this and so I abandoned the project [1].  I agreed with Reinhard oin
> the end.  The basic argument against this was that it is more efficient
> to do this at build time.  If you are using cocoon 2.2, then you can use
> Maven, if you are using cocoon 2.1, it is a little more difficult, but
> can be achieved using Ant tasks.
> Last time I looked at the YUI compressor and shrink safe, they weren't
> Cocoon friendly because both projects actually modify Rhino's code base 
> without changing the package (though that might have changed).
> Maybe the community should decide if this functionality is required.
> Cheers.
> [1]
>> Hello,
>> Has anyone successfully configured Cocoon to do on-the-fly minification
>> of js and/or CSS?
>> There are good java-based minifiers out there, such as Dojo ShrinkSafe
>> and YUI Compressor.
>> Both use Rhino, which Cocoon ships with, I believe.
>> The YUI compressor page says,
>> "If you wish to minify your files on the backend (also known as
>> on-the-fly minification) instead of at build time, you will want to
>> cache the minified files in memory for optimal performance (instead of
>> minifying the same files over and over & minification is a time
>> consuming process) Note that the YUI Compressor can easily be
>> instantiated and used from a Java-based environment (Servlet)."
>> This page:
>> talks about a guy who "used cocoon and the yui compressor to concatenate
>> and minify the js and css files, something that greatly reduced the
>> number of http requests. It also gave us the freedom to write well
>> documented code and sep[a]rate the code into a large number of small
>> files."
>> Those are some great benefits...
>> but how to integrate YUI compressor into Cocoon? Do I need to write a
>> custom generator? And how to provide caching?
>> Thanks for any ideas,
>> Lars
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message