Reputation: 7601
I want to know is it possinle to add ascx file in bundling like
bundles.Add(new ScriptBundle("~/bundles/First").Include(
"~/Script/js.ascx"));
I want to know because suppose I have to add one more file in bundling after product release then I have to build again for that.
Upvotes: 1
Views: 153
Reputation: 12371
Well I can't answer the specific question (haven't tried), but to tackle the "issue":
I want to know because suppose I have to add one more file in bundling after product release then I have to build again for that.
As per the docs on bundling, you have options to include files and even directories..and wildcards:
So:
BundleCollection bundles = BundleTable.Bundles;
bundles.Add((new ScriptBundle("~/bundle/custom")
.IncludeDirectory("~/Scripts/edsf/", "ed*")));
Means:
/Scripts/edsf
"ed"
, in the stated directory, to be in the script bundle, e.g.
If I add a new file, edbar.js
, to the /Scripts/edsf
directory, it will be bundled automatically, and you'll see the version string get updated.
No need to build....
Hth...
Upvotes: 1
Reputation: 15943
No we cannot include ascx file in bundles We use only js and css files for bundling...here is a small explanation why we use bundles
As a Web application becomes more complex, the number of external scripts on which it depends grows significantly. Start with jQuery and some application libraries like Backbone.js (and its dependency, Underscore), then throw in plugins from UI frameworks like Foundation and some form validation scripts—not to mention your app’s code itself!—and you can easily discover your app has dozens of external files, each of which must be loaded on every page refresh.
To combat this problem, developers often use tools called “bundlers”
, which concatenate script files—or stylesheets—together into a single file, thereby reducing the I/O overhead of sending multiple files across the Internet. Many also perform a process known as “minification”, whereby non-essential whitespace is removed and variable names are changed to be as short as possible, resulting in an unreadable—but highly efficient—piece of code.
ASP MVC provides two tailored classes for bundling : ScriptBundle
, for JavaScript files, and StyleBundle
, for CSS. Both of these classes provide built-in minification, thus reducing your total payload even further. You’ll need to specify a unique path for each bundle.
var myBundle = new ScriptBundle("~/bundles/js");
Using this bundle, you can simply add new files (or entire directories!) by using its methods:
myBundle.IncludeDirectory("~/js/vendor/");
myBundle.Include("~/js/app.js");
Once you’re done with each bundle, add it to the collection passed in as a parameter
bundles.Add(myBundle);
Continue this pattern until you’ve configured all of the bundles you’d like.
Upvotes: 2