Compressing the JavaScript and CSS files on the fly using YUI COmpressor

I was trying to build a Servlet and Filter which can be used to minify JavaScript and CSS on the fly using YUI COmpressor. But i ran into this exception. When i was searching for solution to this problem i found WebUtils project which has
following components which can use easily used in J2EE webapp.


  • JSCSSMergeServlet - to merge multiple JS or CSS and serve them in one HTTP request.

  • YUIMinFilter - to compress JS or CSS resources on the fly using YUI compressor.

  • YuiMinTag - Custom tag to compress inline JS and CSS code using YUI compressor in JSPs.





[8/9/10 11:46:59:322 PDT] 0000008d ServletWrappe E SRVE0068E: Uncaught exception thrown in one of the service methods of the servlet: YUICompressorDemoServlet. Exception thrown : java.lang.StringIndexOutOfBoundsException
at java.lang.String.substring(String.java:1088)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.printSourceString(JavaScriptCompressor.java:268)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.parse(JavaScriptCompressor.java:333)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.(JavaScriptCompressor.java:536)
at com.webspherenotes.performance.minfy.YUICompressorDemoServlet.doGet(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1146)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:592)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:524)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3517)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:269)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:818)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1478)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:125)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:387)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:267)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:196)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:751)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:881)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1497)

1 comment:

Rajendra said...

Thanks Sunil. webutilities v0.0.5 is out with efficient caching mechanism (ETag, if-modified-since etc.). It is also now maven resource and available at maven central - http://search.maven.org/#search%7Cga%7C1%7Cwebutilities

We too getting array index exception issue when using yuicompressor as maven dependency and I think yuicompressor 2.4.7 has got that fixed - http://yuilibrary.com/projects/yuicompressor/ticket/2528114