bits about life, coding and stuff
JavaScript files that are served to the user should be compressed and minified, and ideally everything packed into ONE big file. You can do this with some rails plugins (not tested so far), or using the “manual” way of compressing it yourself. (or download a compressed file
I worked with YUI Compressor on compressing a fresh git clone of jqGrid.
From Yahoos developer page:
The YUI Compressor is written in Java (requires Java >= 1.4) and relies on Rhino to tokenize the source JavaScript file. It starts by analyzing the source JavaScript file to understand how it is structured. It then prints out the token stream, omitting as many white space characters as possible, and replacing all local symbols by a 1 (or 2, or 3) letter symbol wherever such a substitution is appropriate
This is a typical call:
With jqGrid, you have many js files that need to be merged together. You can do this manually (sucks) or with some kind of script. For jqGrid, pbor provides an ANT script. Copy yuicompressor, build.xml and build.properties in jqGrid source, change build.properties to mach the yui path (mostly YUICompressor=yuicompressor-2.4.2.jar) and start it via shell> ant.
Voila! Your minified jgGrid is waiting in the dist\ folder for you.
Update: In the tqgrid36 branch, build.xml and build.properties are already there. So you just have to modify the .properties to match your yui path.
Related posts:
4 Responses to Compress JavaScript with YUI Compressor
Jack
November 5th, 2009 at 11:36 pm
Hi Peter,
good post. Do you have an example for how ant can be run from the command line?
Thanks
Jack
November 6th, 2009 at 12:47 am
good post. Could you provide an example of how Ant can be executed from windows command line?
Thanks
Dominik
November 28th, 2009 at 4:25 pm
start -> run -> cd C:\somedir -> ant
Dominik
November 28th, 2009 at 4:25 pm
start -> run -> cmd -> cd C:\somedir -> ant