I wish if i could change registered bundle collection items (JS or CSS files) dynamically after my MVC website published for example by hitting a button. Is it possible and what should we do to achieve this?
any help appreciated.
I wish if i could change registered bundle collection items (JS or CSS files) dynamically after my MVC website published for example by hitting a button. Is it possible and what should we do to achieve this?
any help appreciated.
After some search and try i found a way. I put this snippet in Session_Start but you can use it any where for example in button submit handler. I search for Bundle with a special name, then remove and create a new bundle with that name that i used in my project. (I did it to have new fresh bundle because i can't find any method to remove files from existing bundle and i appreciate if anyone knows how to do) Finally add files to bundle with include method of bundle and add bundle to BundleTable. (You could use IncludeDirectory method too)
Bundle bndl = BundleTable.Bundles.GetBundleFor("~/Content/css");
if (bndl != null)
{
BundleTable.Bundles.Remove(bndl);
}
Bundle bndl2 = new Bundle("~/Content/css");
bndl2.Include("~/Content/site.css", "~/Content/secondStyles.css", ... );
BundleTable.Bundles.Add(bndl2);
At the last it's useful to read this article for working with bundles. Asp.net MVC 4 performance optimization with bundling and minification
Additional answers appreciated. Good Luck.