1
votes

What is the expected behaviour of bundling / minification when a local minified version of a file is and is not present?

I assumed that, when a local .min.js file is found it will just use that (when optimized for release) and if debug it will use the other. When optimized for release but no .min.js file is found, I thought it will minify that file accordingly.

However, I have found that even though I have a .min.js file in my scripts folder, that which is output in the bundle (in release) is not the same as that - it has been altered.

I should add that these have been added as ScriptBundles in the Bundle.config and all transforms / ignore lists etc have been left at the defaults.

Question arises in the case of a 3rd party library such as jQuery. I wouldn't want the files they supply to be minified by the bundling process - just to use the minified files that have been supplied.

Thanks.

2
you can minify your version of jquery and the benefit is that when you do so you are sure that the file is there, but also you can add reference to the minified with the risk that someone may remove it and you will loose jquery. The reason you have the full jquery is that you can debug it in dev and deploy the minified, also for advanced user you can change it to do what you want (not advisable but still possible)Jack M

2 Answers

0
votes

Your assumptions are correct.

If the local minified version is present, when bundling occurs, that is the version that will be used. It will be put through the minification again, and you can tell because it removes the licensing comments that jQuery says you must keep (as detailed in How can I preserve comments that matter in MVC 4 style bundling?) and also may rename variables.

If the local minified version is not present, then it will use the unminified version, which will be put through bundling/minification.

So in both cases, it will be put through minification.

0
votes

By default when registering script bundles using the ScriptBundle class, all included files will be minified again regardless of .min.js. The reason for this is because ScriptBundle uses a specific IBundleTransform implementation which always minifies the javascript file.

To override this behaviour a dummy implementation can be used:

public class NoTransform : IBundleTransform
{
    public void Process(BundleContext context, BundleResponse response)
    {
    }
}

Registering the bundle:

bundles.Add(new Bundle("~/bundles/jquerynotransform", new NoTransform()).Include("~/Scripts/jquery-{version}.js"));