0

I have MVC solution and have a lot of JS and CSS for all of website, when the page loading, all of JS and CSS is also loading, but some of page only need some of specific JS or CSS in bundles. Ex:

bundles.Add(new ScriptBundle("~/scripts/jquery").Include(
            "~/Scripts/JQuery/jquery-1.9.1.js",
            "~/Scripts/JQuery/jquery-ui-1.8.24.js",
            "~/Scripts/JQuery/jquery.minicolors.js",
            "~/Scripts/JQuery/jquery.fontselector.js"));

In page A I render script like that:

 <asp:PlaceHolder runat="server">
      <%: Scripts.Render("~/scripts/jquery") %>
 </asp:PlaceHolder>

But in page B, I want only load jquery-1.9.1.js, not load to all js in bundles. So my question is how to load specific file js in page B.

1
  • 4
    Add a new script bundle that only includes jquery-1.9.1.js, and load only that script bundle. Then I suggest that you check if there is actually any performance difference. It might be better to just include them all for simplicity because excluding the other three files makes very little difference performance wise, and selectively including css and js on different pages can make debugging a nightmare. Also, consider forcing bundling so that you can debug it stackoverflow.com/questions/16030905/… Commented Mar 13, 2017 at 1:36

1 Answer 1

1

You can add as many bundles as you need:

bundles.Add(new ScriptBundle("~/scripts/jquery").Include(
        "~/Scripts/JQuery/jquery-1.9.1.js",
        "~/Scripts/JQuery/jquery-ui-1.8.24.js",
        "~/Scripts/JQuery/jquery.minicolors.js",
        "~/Scripts/JQuery/jquery.fontselector.js"));

bundles.Add(new ScriptBundle("~/scripts/justjquery").Include("~/Scripts/JQuery/jquery-1.9.1.js"));

And in your view:

 <asp:PlaceHolder runat="server">
      <%: Scripts.Render("~/scripts/justjquery") %>
 </asp:PlaceHolder>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.