Welcome to AspAdvice Sign in | Join | Help

Save that bandwidth and download times

Here is a tip that I thought I would share.

I believe we all as software developers want to turn out the best product we possibly can and one way we can do this is in the area of performance. Let us assume you have many javascript libraries that are part of your project and you want to compress these libraries at the time you deploy your project. I found a great tool to accomplish exactly this named ESC.

"ESC is an ECMAScript pre-processor written in JScript, enabling an unlimited number of external scripts to be compressed/crunched into supertight, bandwidth-optimized packages. Featuring several compression-techniques such as comment removal, whitespace stripping, newline stripping and variable substitution ESC can reduce the overall size of your code with up to ~45%. Single, multiple scripts and even directories with scripts can be merged together at the compression level you decide."

I use Visual Studio 2005 Web Deployment Projects for my build and deployment process.

All you need to do in place the ESC script in you solutions root directory and created a batch file to perform the compression of your JavaScript files.

Example batch file:
cscript C:\MyDevelopment\SourceCode\MyProject\esc.wsf -l 3 -ow C:\MyDevelopment\SourceCode\MyProject\v1.0\V1.0_Release\Release\scripts\ThemePreview.js "C:\MyDevelopment\SourceCode\MyProject\v1.0_Release\Release\scripts\ThemePreview.js"

Now all that remains is to add this action to the deployment project. I accomplish this step in the action "AfterBuild".

Example:
<Message Text="Standby... Compressing JavaScript." Importance="high"></Message>
<Exec Command="C:\MyDevelopment\SourceCode\MyProject\v1.0\compress_js.bat"></Exec>

Now all that remains is to deploy the project itself with the tightly compressed JavaScript files. However deployment is another topic in itself. Good luck and I hope you find this tip useful.

Sponsor
Published Thursday, March 29, 2007 11:03 AM by sswafford

Comments

New Comments to this post are disabled