I have a weird issue with the mvc4 bundler not including files with extension .min.js
In my BundleConfig class, I declare
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/Scripts/jquery")
.Include("~/Scripts/jquery-1.8.0.js")
.Include("~/Scripts/jquery.tmpl.min.js"));
}
In my view, I declare
<html>
<head>
@Scripts.Render("~/Scripts/jquery")
</head><body>test</body>
</html>
And when it renders, it only renders
<html>
<head>
<script src="/Scripts/jquery-1.8.0.js"></script>
</head>
<body>test</body>
</html>
If I rename the jquery.tmpl.min.js to jquery.tmpl.js (and update the path in the bundle accordingly), both scripts are rendered correctly.
Is there some config setting that is causing it to ignore '.min.js' files?
For my case, I was using the (wonderful!) Knockout.js library which comes as Debug/Non versions:
To make this work, I included "Knockout-{Version}.js" (non-debug) in my Bundle and got the .debug. js file in Debug mode.
If all you have is a minified version of a file, the simplest solution I've found is to copy the minified file, remove .min from the copied file's name, then reference the non-minified file name in your bundle.
For example, let's say you purchased a js component and they gave you a file called some-lib-3.2.1.min.js. To use this file in a bundle, do the following:
Copy some-lib-3.2.1.min.js and rename the copied file to some-lib-3.2.1.js. Include both files in your project.
Reference the non-minified file in your bundle, like this:
Just because the file without 'min' in the name is actually minified shouldn't cause any issues (other than the fact it's essentially unreadable). It's only used in debug mode and gets written out as a separate script. When not in debug mode the pre-compiled min file should be included in your bundle.
An easy way just Rename the .min file for example you have abc.min.css than just rename this file to abc_min.css and add this to your bundle. I know its not the right way to do it, but just a temporary solution. thanks and happy coding.
I have found a good solution that works at least in MVC5, you can just use
Bundle
instead ofScriptBundle
. It does not have the smart behavior ofScriptBundle
that we don't like (ignoring .min, etc.) in this case. In my solution I useBundle
for 3d party scripts with .min and .map files and I useScriptBundle
for our code. I have not noticed any drawbacks of doing it. To make it work this way you will need to add original file e.g. angular.js, and it will load angular.js in debug and it will bundle the angular.min.js in release mode.Folks I would just keep it simply until Microsoft gets it act together
Try this
In RegisterBundles create this bundle for Kendo
In _Layout.cshtml put this:
This way we get best of bundles in Production and a reference in Debug
Fix it up when Microsoft fixes their MVC 4 Code
To render
*.min.js
files, you must disableBundleTable.EnableOptimizations
, which is a global setting that applies to all bundles.If you want to enable optimizations for specific bundles only, you can create your own
ScriptBundle
type that temporarily enables optimizations when enumerating files in the bundle.Use
OptimizedScriptBundle
instead ofScriptBundle
for bundles whose minified file should always be used, regardless of whether a non-minified file exists.Example for Kendo UI for ASP.NET MVC, which is distributed as a collection of only minified files.