crichavin
crichavin

Reputation: 4572

MVC4 app is auto minifiy js files, no want

I did something that is now causing my JS and CSS files to be minified when the app runs. I have no idea how this became so. I was not going for this result and was not trying to make it happen in anyway as my app is still in development mode. (Good to know this is somehow possible though when I move to Production mode :)

It seems to have happened after I did a Publish command in Visual Studio 2012. But I can't be sure that was the culprit.

So know when I am trying to debug my javascript files, I can't because they have been minified.

What causes this? How do I turn it off?

Here is some of my code in how I am including the js files.

In my layout I have:

@Scripts.Render("~/bundles/OTIS")

In bundleConfig I have:

bundles.Add(new ScriptBundle("~/bundles/OTIS").Include(
                    "~/Scripts/OTIS.Core.*",
                    "~/Scripts/lightbox/jquery.lightbox-0.5.min.js"
                    )
                );

My OTIS.Core.js file is not minified.

Yet, looking at the generated html of the view, I see:

<script src="/bundles/OTIS?v=gUSAZPNxeuLWr9FClJzjCG5bqrO4n2Dj44QgtT4jL-01"></script>

Upvotes: 1

Views: 518

Answers (2)

Ray Cheng
Ray Cheng

Reputation: 12576

in your bundle config, put the followings to the bottom of RegisterBundles:

#if(DEBUG)
    BundleTable.EnableOptimizations = false;
#endif
#if(!DEBUG)
    BundleTable.EnableOptimizations = true;
#endif

this will ensure your js and css be minified in non-debug build. but if you build in debug, the scripts will not be minified.

Upvotes: 1

crichavin
crichavin

Reputation: 4572

Another way Minifying is controlled is by setting the debug flag in the web.config file, i.e.

<compilation debug="true" targetFramework="4.5" />

If set to false, minification will occur. I found this article helpful for a more in depth explanation.

Upvotes: 1

Related Questions