Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7414503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:06:38+00:00 2026-05-29T07:06:38+00:00

Is it better to load ALL my resources in my base layout/template view, or

  • 0

Is it better to load ALL my resources in my base layout/template view, or directly in the partial view I load in ajax?

Exemple:

_layout:

[...]

    <head>
        <script src="file.js"></script>
        <link href="file.css"></link >
    </head>

[...]

OR

_layout:

[...]

    <head>
    </head>

[...]

partialView (loaded later in AJAX):

<div>
    <script src="file.js"></script>
    <link href="file.css"></link > 
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:06:40+00:00Added an answer on May 29, 2026 at 7:06 am

    What you would normally be doing is pushing some script resources into a list on the viewbag, and then get your template to go through that list and generate the script include for you.

    On the partial:

    @{
        ViewBag.ScriptIncludes = ViewBag.ScriptIncludes ?? new List<string>();
        ViewBag.ScriptIncludes.add("script1.js");
    }
    

    In the layout (_Layout.cshtml)

    @if (ViewBag.ScriptIncludes != null)
    {
        foreach (string url in ViewBag.ScriptIncludes)
        {
            <script src="@url" type="text/javascript"></script>
        }
    }
    

    In normal circumstances this allows you to associate scripts with partial which is quite nice, and is a good idea if you are only refreshing a partial which exists on the page on page load.

    The scripts should be preloaded on the page. You shouldn’t be reloading scripts by getting a script resource via ajax and injecting it into the page. Ideally you wouldn’t be getting html over ajax either, but some people find this acceptable. You only want to inject the html into the page and not more scripts. If you have event handlers on the items inside the partial view, consider attaching the event handlers to the container instead of the elements individually.

    However, given that you are reloading potentially any view, I think you are better off including your scripts in the head. This will ensure that you don’t find any conflicting scripts later on. Your site is essentially an application that costs the user a small overhead to load initially but does not need to be refreshed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it better to use $.get(http://www.example.com/mydirectory, function(data) { $(.someclass).html(data); }); or $('.tripPlannerBottom').load(http://www.example.com/mydirectory); any speed
Is there a better way to load a large amount of Google Web Fonts
I've an xml file that I would avoid having to load all in memory.
I need to load all the assemblies from DLLs in a directory. My basic
Better yet, how can I make My Computer always open in Explorer as well?
Or better said: When to use array as a field data type in a
Even better would be if autoResize in latest branch would work as intended, but
For better description, +-----------------------+ | Desktop (screen) | | | | | | +----------+
any better way to write this ? $(this).parent().parent().find( dd ul).toggle(); update.. I am trying
Is better to use the below statement Convert.ToInt32(0 + stringValue) If not then why?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.