Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to minify the ASP.NET generated Javascript?

What's the best way to minify the ASP.NET generated Javascript, such as the ones served by webresource.axd, in ASP.NET 3.5 at runtime? I tried using the MbCompression module but it's not working with those resources.

like image 987
craigmoliver Avatar asked Nov 03 '09 22:11

craigmoliver


People also ask

How do you minify a JavaScript file?

To minify JavaScript, try UglifyJS. The Closure Compiler is also very effective. You can create a build process that uses these tools to minify and rename the development files and save them to a production directory.

Should you minify JavaScript?

Minifying strips out all comments, superfluous white space and shortens variable names. It thus reduces download time for your JavaScript files as they are (usually) a lot smaller in filesize. So, yes it does improve performance. The obfuscation shouldn't adversely affect performance.

Why should you minify your JavaScript scripts before publishing them?

The sole benefit of minified JavaScript code is allowing a client to download fewer bytes, enabling the page to load faster, use less battery, use less of a mobile data plan, etc. This is usually be done as a build step when releasing code to a web server. Many tools, like uglify for example, exist to do this for you.


1 Answers

If you want to minify the ASP.NET AJAX JavaScript, ensure that you've updated the compilation section of your web.config to turn off Debug mode:

<compilation debug="false">

This will ensure that the ScriptResource files are minified, however unless you've supplied minified versions of your JS files, these won't be touched.

like image 185
Zhaph - Ben Duguid Avatar answered Sep 21 '22 10:09

Zhaph - Ben Duguid