0

I have the following bundling config:

bundles.Add(new ScriptBundle("~/bundles/superfish").Include(
            "~/Scripts/superfish.js",
            "~/Scripts/supersubs.js",
            "~/Scripts/hoverIntent.js"));

bundles.Add(new StyleBundle("~/bundles/superfish/css").Include(
            "~/Content/megafish.css",
            "~/Content/superfish-navbar.css",
            "~/Content/superfish-vertical.css",
            "~/Content/superfish.css"));

I have the following files in the /Scripts folder:

"~/Scripts/superfish.js",
"~/Scripts/superfish.min.js",
"~/Scripts/supersubs.js",
"~/Scripts/hoverIntent.js"

Questions:
a) Should I or not include the ".min" file in the bundle?
b) If not, what is the rule that automatically idenfity the min file? Say, could I use the
~/Scripts/superfish-src.min.js instead of
~/Scripts/superfish.min.js?
Or sometimes the min files are included all in a "minified" folder. How does the framework know where to search for them?
c) is there a min version for the css files?

serge
  • 13,940
  • 35
  • 121
  • 205
  • [Here](http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification) is a lot of info - in "release" mode the "min" version is used – Hans Kesting Feb 28 '14 at 15:10
  • in "release" the "min" version is used *instead of what file*? or all files terminated with .min are used, how about files that have not the minified versions? – serge Feb 28 '14 at 15:13
  • 1
    The way I understand it (from that page): when you register "superfish.js", then in *release* mode (if it's available) "superfish.min.js" is used, else the original file is minified. In *debug* mode no minification is used, to enable debugging. – Hans Kesting Feb 28 '14 at 15:57

1 Answers1

1

ASP.NET MVC both combines and minifies JS and CSS. It has two built in handlers for this: JsMinify and CssMinify, respectively. There's nuget packages that allow you to substitute these for other minification algorithms, such as JsMin, YUI, etc.

If a file with .min exists, it is assumed that you have handled the minification yourself, and that file will be combined (but not minified again) with the rest of your resources.

Both bundling and minification occurs only in release configuration. So you would have to publish and deploy your app with the release config, before you'll see anything happen. In debug config, MVC serves up each resource, unmodified, individually.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • So, if I have "superfish.js" and "superfish-src.min.js"... Will it be considered as minified version if the "superfish.js" file? Or what if my minified file is contained in the "minified" folder? How MVC searches for a existing minified version of "myFile.js" file? – serge Feb 28 '14 at 15:32
  • 1
    No, it must be an exact match. The minified version of `superfish.js` is `superfish.min.js`. Nothing else will apply. Also, the minified version must be in the same folder as the non-minified version. MVC will not dig into other folders. However, unless there's a good reason to handle minification yourself, it's better to just only include the non-minified versions and let MVC handle it all. – Chris Pratt Feb 28 '14 at 15:35
  • Also, you should never directly reference an already-minified file in your bundle. If you specify the full name of the minified file, the bundler *will* treat it as normal and minify it *again*, which obviously is going to break stuff. – Chris Pratt Feb 28 '14 at 15:37
  • I understand. When using NuGets, there is no really way to control if the min files are not not added... Thanks, is a good point! – serge Feb 28 '14 at 15:41