Maintaining minified .js files in Visual Studio 2012

Perhaps this is common knowledge, but I just figured it out (accidentally) and its pretty damn awesome! If you maintain a regular .js file, and then create a copy of it .min.js with a compressed copy of your code, Visual Studio will maintain that minified version automatically whenever you make changes to your original!  It will create a .map file that it uses to keep track of the differences between your source and minified versions (variable names, etc). Whenever you make an edit to your regular .js file, those changes will be reflected in the .min version!

For those of us using basic one-off files and don’t want to deal with bundling (or aren’t using .net 4.5 yet) this is pretty handy!

Note: This is most likely the result of the Web Essentials plugin and not Visual Studio itself.  It was brought to my attention that using Web Essentials,  you can also minify and bundle your js and css files (via right click menus)!

2 thoughts on “Maintaining minified .js files in Visual Studio 2012

  1. Web Essentials has option to right-click and minify, however is there a way to setup to do automatically after editing the js file?

    Like

    • I’m not sure about that in Visual Studio, but something like that works really well when you use Grunt.js. If you check my main article on the homepage, you can see a breakdown of how I use Grunt in another project to automate things like minification, concatenation, etc on modification of .js files.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s