Issue Details (XML | Word | Printable)

Key: DWR-32
Type: New Feature New Feature
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Joe Walker
Reporter: Joe Walker
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
DWR

Add more agressive inline javascript compression

Created: 29/Mar/07 10:25 AM   Updated: 17/Mar/08 02:47 PM   Resolved: 17/Mar/08 02:47 PM
Component/s: core
Affects Version/s: None
Fix Version/s: 3.0.RC1


 Description  « Hide

Sort Order: Ascending order - Click to sort in descending order
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?

Joe Walker added a comment - 11/Feb/08 09:17 PM

I guess so - we could always have an interface for JS compression that various impls can use.

Joe Walker added a comment - 22/Feb/08 04:37 PM
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.

David Marginian added a comment - 22/Feb/08 04:59 PM

David Marginian added a comment - 22/Feb/08 05:08 PM
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?

Chris Holland added a comment - 22/Feb/08 05:38 PM
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();

David Marginian added a comment - 22/Feb/08 06:36 PM
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.

Chris Holland added a comment - 22/Feb/08 08:10 PM
Oh I see, that makes sense.