1

I'm developing a simple CMS with Theme Support. I'm trying to find a way to create css and js bundles for each theme.

I don't want to create Bundles in App_Start.

Something like put my code in _ViewStart.html like this :

@{ Layout = "~/Views/Shared/_Layout.cshtml"; Add(new ScriptBundle("~/bundles/myscripts").Include( "~/Scripts/myscript1.js", "~/Scripts/myscript2.js")); //and so on... } 

Is there any way to do this...?

1 Answer 1

2

Eventually I found the answer:

System.Web.Optimization.BundleTable.Bundles .Add(new ScriptBundle("~/bundles/myscripts").Include(...)); 

Just for note : If you really don't need to create bundles in controller/view, for performance manners its best place to create bundles is in app_start.

Sign up to request clarification or add additional context in comments.

1 Comment

That works, but it will run on every page request, kinda crappy. So what I did for my solution is I made a static method on a helper class that accepts bundles and registers them. Then it sets "BundlesLoaded" to true. And BundlesLoaded is true the view code doesn't run with an if block on !BundlesLoaded.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.