views:

429

answers:

2

We have a handful of ASP.net pages that include more than 50+ lines of javascript specific to that page. We'd like to minify that javascript during our CruiseControl build process.

We already use the YUI Compressor to compress our full javascript and css files. But we can't figure out how to do the Inline javascript.

Is there an MSBuild task to spin through asp.net pages and minify the javascript?

+1  A: 

You won't be able to do this without custom coding. Easiest way would probably to create a PreBuild step in the msbuild file which spits through all the .aspx files and regexes all the javascript out. Then use YUI to minify the content and replace the original by the minified version.

You might also want to check MbCompression which compresses alot including your asp.net pages, although I don't believe it also minifies the inline javascript.

Jan Jongboom
+1  A: 

I would extract javascript into methods and move them into .js files. and call the functions instead with the relevant parameters from the pages. Not a complicated procedure and much easier to maintain (less code). You can also benefit from client side content caching.


Also: Not sure if it helps but Google's Closure looks really good.

http://code.google.com/closure/

Compression options: http://code.google.com/closure/compiler/docs/api-tutorial3.html

Available as Java executable or web service.

Serkan