The way that bundling and minification is done in Asp.Net MVC is through dynamic processing at runtime. When you create a bundle, it can be injected into any Asp.Net page. If you are in Debug Mode, the bundler will send out each item in the bundle in their full form, for ease of debug. If you are in Release Mode, the bundler automatically parses the contents of the individual files in the bundle into a single in memory filestream, which it then minifies. There is no need to explicitly include both the full and minified versions of your css/javascript files in the project. However, as per the ASP.Net Documentation:
The bundling framework follows several common conventions such as:
- Selecting “.min” file for release when “FileX.min.js” and “FileX.js” exist.
- Selecting the non “.min” version for debug.
- Ignoring “-vsdoc” files (such as jquery-1.7.1-vsdoc.js), which are used only by IntelliSense.
Basically, if you have both the full and minified versions, then the framework will prefer the use of the pre-minified version over minifying the file itself.
Upon loading your page in Release Mode, the effect of bundling and minification presents itself as a single css or js file stream for the entire bundle, represented by single call to the server, e.g. http://localhost/MvcBM_time/bundles/AllMyScripts?v=r0sLDicvP58AIXN_mc3QdyVvVj5euZNzdsa2N1PKvb81
.
Effectively, a unique route is created matching the name of the bundle (AllMyScripts
in this example). The query string v
has a value token that is a unique identifier used for caching. As long as the bundle doesn't change, the ASP.NET application will request the AllMyScripts
bundle using this token. If any file in the bundle changes, the ASP.NET optimization framework will generate a new token, guaranteeing that browser requests for the bundle will get the latest bundle.
As for including files from multiple directories, the easiest method would be to use wildcard pattern matching. The virtual path specified in the Include
method and the search pattern in the IncludeDirectory
method can accept one *
wildcard character as a prefix or suffix to in the last path segment. The search string is case insensitive. The IncludeDirectory
method has the option of searching subdirectories.