Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minify inline javascript during build for ASP.net?

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?

like image 884
Paul Lemke Avatar asked Dec 22 '09 16:12

Paul Lemke


2 Answers

There is an interesting blog and NuGet package called undleMinifyInlineJsCss to handle this

http://weblogs.asp.net/imranbaloch/archive/2012/07/25/bundling-and-minifying-inline-css-and-js.aspx

like image 50
Stephen Montgomery Avatar answered Nov 06 '22 01:11

Stephen Montgomery


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.

like image 44
Serkan Avatar answered Nov 06 '22 01:11

Serkan