|
[
Permalink
| « Hide
]
David Marginian added a comment - 11/Feb/08 08:44 PM
If we use shrinksafe aren't we going to have a runtime dependency on custom_rhino.jar?
I guess so - we could always have an interface for JS compression that various impls can use. From the mailing list:
We've been using Include to make compressing and including scripts really easy. It would work great with DWR and allow users to just include the scripts they need, then compress a production version of those scripts automatically. Check it out at http://javascriptmvc.com/include. I hope you find it as useful as we have. Another option:
http://developer.yahoo.com/yui/compressor/ Joe I can work on the compressor interface and implementations. I am thinking we can have a implementation for Shrinksafe and Yahoo compressor now. Any more come to mind?
To get both going you'll have to be super-careful about rhino.jar vs custom_rhino.jar. I've run into issues when migrating my optimized static resource servlet from using shrinksafe to yui compressor, simply because i had both vanilla rhino which yahoo builds on-top of, and shrinksafe's custom rhino jars in my class path.
I'd highly recommend going with YUI though, as from what i've seen it compresses at least as well as shrinksafe, and is far cleaner/easier to integrate. assuming scriptSource is a String representation of your JS source code .... here's a basic integration i did with YUI compressor: StringReader resourceReader = new StringReader(scriptSource); JavaScriptCompressor jsCompressor = new JavaScriptCompressor( resourceReader, new ErrorReporter() { public void warning(String message, String sourceName, int line, String lineSource, int lineOffset) { if (line < 0) { log.warn(message); } else { log.error("\n" + line + ':' + lineOffset + ':' + message); } } public void error(String message, String sourceName, int line, String lineSource, int lineOffset) { if (line < 0) { log.error(message); } else { log.error(line + ':' + lineOffset + ':' + message); } }// public EvaluatorException runtimeError(String message, String sourceName, int line, String lineSource, int lineOffset) { error(message, sourceName, line, lineSource, lineOffset); return new EvaluatorException(message); } }//error reporter );//JavaScriptCompressor constructor call; resourceReader.close(); StringWriter writer = new StringWriter(); jsCompressor.compress(writer, 20000, false, false, false, false); //up to you here ... :) //minifiedTextResource = writer.toString().getBytes("UTF-8"); writer.close(); Thanks Chris.
I think the plan is to create a JSCompressor interface and create a few implementations (Yahoo Compressor, Shrinksafe). By default no changes will be made to how things work currently. The end user will be responsible for changing a configuration and choosing a compression implementation. They will also be responsible for adding the appropriate libraries to their classpath. Oh I see, that makes sense.
|
||||||||||||||||||||||||||||||||||