DWR

Add more agressive inline javascript compression

Details

  • Type: New Feature New Feature
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 3.0.RC1
  • Component/s: core

Activity

Hide
David Marginian added a comment - 11/Feb/08 8:44 PM
If we use shrinksafe aren't we going to have a runtime dependency on custom_rhino.jar?
Show
David Marginian added a comment - 11/Feb/08 8:44 PM If we use shrinksafe aren't we going to have a runtime dependency on custom_rhino.jar?
Hide
Joe Walker added a comment - 11/Feb/08 9:17 PM

I guess so - we could always have an interface for JS compression that various impls can use.
Show
Joe Walker added a comment - 11/Feb/08 9:17 PM I guess so - we could always have an interface for JS compression that various impls can use.
Hide
Joe Walker added a comment - 22/Feb/08 4: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.
Show
Joe Walker added a comment - 22/Feb/08 4: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.
Hide
David Marginian added a comment - 22/Feb/08 4:59 PM
Show
David Marginian added a comment - 22/Feb/08 4:59 PM Another option: http://developer.yahoo.com/yui/compressor/
Hide
David Marginian added a comment - 22/Feb/08 5: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?
Show
David Marginian added a comment - 22/Feb/08 5: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?
Hide
Chris Holland added a comment - 22/Feb/08 5: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();
Show
Chris Holland added a comment - 22/Feb/08 5: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();
Hide
David Marginian added a comment - 22/Feb/08 6: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.
Show
David Marginian added a comment - 22/Feb/08 6: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.
Hide
Chris Holland added a comment - 22/Feb/08 8:10 PM
Oh I see, that makes sense.
Show
Chris Holland added a comment - 22/Feb/08 8:10 PM Oh I see, that makes sense.

People

Dates

  • Created:
    29/Mar/07 10:25 AM
    Updated:
    17/Mar/08 2:47 PM
    Resolved:
    17/Mar/08 2:47 PM