最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net mvc - Minifying Javascript on Visual Studio 2010 on release mode - Stack Overflow

programmeradmin0浏览0评论

I have a ASP.NET MVC 2 project on Visual Studio 2010. I want to be able to use my plain javascript files in debug mode so I can understand what's going on when debugging, but I want to used a minified/pressed version when using release mode.

I was planning to create some extenders to include the js files in each page, something like:

In that extender method I would determine whether I am on debug or release mode and pick the appropiate JS file. The disadvantage here is that I would end up manually pressing/minifying the JS every time I change something.

Is there an automated way to press/minify and include the JS file when piling in release mode?

I have a ASP.NET MVC 2 project on Visual Studio 2010. I want to be able to use my plain javascript files in debug mode so I can understand what's going on when debugging, but I want to used a minified/pressed version when using release mode.

I was planning to create some extenders to include the js files in each page, something like:

In that extender method I would determine whether I am on debug or release mode and pick the appropiate JS file. The disadvantage here is that I would end up manually pressing/minifying the JS every time I change something.

Is there an automated way to press/minify and include the JS file when piling in release mode?

Share Improve this question asked Jun 10, 2010 at 14:23 Arturo MolinaArturo Molina 1,05911 silver badges22 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

The best option is to press files by running a post build task from visual studio: Compressing JS files as part of your build process

You might want to take a look at the Yahoo YUI pressor.

You could use a post-build event and the Microsoft AJAX minifier or the YUI Compressor.

I manage a PHP development shop but we do this very same thing. In our development environments, our code is not obfuscated or minified. To push our changes to our live site, I coded a perl script that updates our version control and then invokes the YUI Compressor to minify the JavaScript and CSS before placing it in our live static directories.

As an aside, you may also want to look into merging your CSS and JavaScript on publish as well for added performance. After we minify our static content, we concatenate it into similar files based on purpose. For example, we have about 20 JavaScript files that end up in a file called 'global.js' on our production server. Our code is written such that development environments include all JavaScript files in our js/global/ folder separately, but on production it includes everything in js/global/ as 'js/global.js'. Then, we just iterate through the minified files during publish and concatenate their contents into js/global.js.

The benefit to the merge approach is fewer JavaScript and CSS files for the users to download which means faster page loads. This approach also allows you to split your JavaScript into separate files in your development environment by purpose for easier maintenance.

发布评论

评论列表(0)

  1. 暂无评论