Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How MVC4 uses bundling virtual path?

In the Microsoft MVC4, I see something called bundling for minifying and caching static resources such as CSS and JavaScript. In the ScriptBundle method I see the first parameter that called virtual path and it should be relative only.

bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-1.*"));

For example, ~/bundles/jquery in above code.

I have one question, how bundling uses this virtual path? Is this used for something like file caching?

like image 734
Afshin Mehrabani Avatar asked Oct 20 '12 13:10

Afshin Mehrabani


2 Answers

"The new ScriptBundle object is given a virtual path which can be anything you like. It effectively acts as a name by which the bundle can be identified. It does not have to match an existing path in the web site folder structure."

Taken from http://www.mikesdotnetting.com/article/197/optimising-asp-net-web-pages-sites-bundling-and-minification

@Richard, in case you are still looking for the answer.

like image 197
Valeriya Avatar answered Oct 20 '22 15:10

Valeriya


Javascript and CSS Minifying/Bundling

Now, the way the JS/CSS minifying works is that it will dynamically inspect all your files, read them, minify them and then cache the result to be served later. This allows us to modify our files and have all the files re-minified. When one of our JS/CSS files get modified again, this process will restart until either the cache expires or a file change.

Also look at this post ScriptBundle and StyleBundle names and includes and link in this post for more details.

like image 24
webdeveloper Avatar answered Oct 20 '22 15:10

webdeveloper