Reputation: 1
I am working on an asp.net mvc-5 web application . and inside my bundle i define the following (where i am referencing .js and min.js files):-
bundles.Add(new ScriptBundle("~/bundles/jsTemplate").Include(
"~/bower_components/moment/min/moment.min.js",
"~/bower_components/fullcalendar/dist/fullcalendar.min.js",
"~/js/jquery.dataTables.min.js",
"~/bower_components/responsive-tables/responsive-tables.js",
"~/bower_components/bootstrap-tour/build/js/bootstrap-tour.min.js",
"~/js/jquery.raty.min.js",
));
where i am referencing some .js & min.js files, so how will bundle work in this case on production server ?. as i know bundle (when debug=false) will do these 2 main tasks:- 1. combine all the scripts inside the bundle into a single file 2. minify the combined file.
now in my case the bundle contain minify and non-minify files, so does this mean that the minify files will get an additional minification ? or minified files can not be minified and the bundle will deliver the .min.js as is to the client ?
Upvotes: 0
Views: 57
Reputation: 506
The bundle will minify all your files first(if not minified already) and then join them in a single file that will be served to the browser, instead of several independent files.
If your already minified files have variables than can be further minified, it will do so, as well as removing additional spaces and line breaks.
On a side note, debug=false is not the only variable you can play with to test this. You can also use EnableOptimizations inside your BundleConfig class, and with the code below you can test it in your local environment if you have a connectionString you can refer to, or modify it to your needs.
using (DbContext Db = new DbContext())
{
if (Db.Database.Connection.ConnectionString.ToLower().Contains("localdb"))
BundleTable.EnableOptimizations = false;
else
BundleTable.EnableOptimizations = true;
}
If EnableOptimizations is false, the server will send all the original files individually to the browser (exactly the way you have them, minified or not, but independent).
Edit: I just tested it a bit more to make sure, and yes the bundle does not care if you have the .min. in the filename, it will still try do minify the file anyway, and additionally I found a feature I did not know it was possible, it changed my testing code from this:
var foo = function(){
var x = "Hello";
console.log(x);
}
to this:
var foo;foo=function(){console.log("Hello")}
Did not modify the foo because it is in the global namespace? But more surprisingly, it go rid of the x
variable.
weird!?
Upvotes: 1