Wednesday, July 18, 2012

Minification and bundling in ASP.NET: WebGrease

When installing the latest version of the Microsoft.AspNet.Web.Optimization package(before the Microsoft.Web.Optimization package)  I noticed a dependency on an assembly called WebGrease.

So I started to look around what it is and found the following 2 blog posts:

What is WebGrease?

WebGrease is a suite of tools focused on assisting web developers with optimizing the "static" asset files (JavaScript, CSS) of a web application. The features the initial version includes are:

  • Minification of JavaScript & CSS files
  • Validation of JavaScript files
  • Creation of image sprites from images reference in CSS files.
  • Bundling of CSS & JavaScript files.
  • Auto-version naming of files.

The Web Optimization library uses some of the features WebGrease offers(currently only the Minification features for CSS and JavaScript). In order to use all of the features in WebGrease, there is a command line tool included with the nuget package(WG.exe).

wg.exe <operation switch> -in:<input file/folder> -out:<output file/folder>

The valid operation switches of WG.exe are:

  • -m : Invokes the minification operation on the file(s).
  • -v : Runs a validation pass on javascript file(s) and output the results to the console.
  • -s : Processes css file(s) for images and will attempt to create a image sprite out of them, and create updated copies of the css file(s).
  • -b : Bundles files together into a single output file.
  • -a : This switch will rename files based on their content (hash), and generate a lookup xml file for mapping between the original name and new name.

5 comments:

Donald Henderson said...

Your post is so interesting. and it is more useful and helpful for me. Thanks for share this valuable post.

Anonymous said...

Thanks for great post.

Kevin Knowles said...

This article talks about web grease about how and .net developer can use these techniques in .net development work.

Leslie Lim said...

First time I commented in a blog! I really enjoy it. You have an awesome post. Please do more articles like this. I'm gonna come back surely. God bless.

Rica
www.imarksweb.org

williamson said...

Hi

Global Incorporate involves researched and knowledgeable infromation which enhaces the facts of Digital Marketing. It highlights on the key aspects of the Digital World together with SEO and Social Media Strategies.