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

  • Home
  • SEARCH
  • 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 9250965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:34:45+00:00 2026-06-18T10:34:45+00:00

For an MVC ASP.NET application, I am adding a javascript file to the _Layout.cshtml

  • 0

For an MVC ASP.NET application, I am adding a javascript file to the _Layout.cshtml file in the following manner –

        function loadJS() {

            var el = document.createElement("script");
            el.src = "/Scripts/script.js";
            document.body.appendChild(el);
        }

        if (window.addEventListener)
            window.addEventListener("load", loadJS, false);
        else if (window.attachEvent)
            window.attachEvent("onload", loadJS);
        else window.onload = loadJS;

The purpose of this is to only load the script after the DOM has loaded.

Two questions –

  1. Will script.js be cached by the first page that uses _Layout.cshtml?
  2. If script.js is cached, does that mean all the following pages that use _Layout.cshtml will not have to retrieve script.js from the server? That the pages that use _Layout.cshtml will be able to use the client side cached version of script.js?

Thanks!

  • 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-06-18T10:34:46+00:00Added an answer on June 18, 2026 at 10:34 am

    Yes, when the file is requested, the file will be cached by the browsers. Then the next time the file is requested, the browser will first check its cache and use that one instead of making a request to the server.

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

Sidebar

Related Questions

I'm adding an object to a list within an ASP.NET MVC 3 application using
I've got a basic ASP.NET MVC 2 application. I've got adding and editing rows
I am adding authentication to my web application. It is an asp.net mvc single
I have an ASP.NET WebForms application that I'm adding some ASP.NET MVC to. I
i have the following situation. I am developing a MVC 3 asp.net application. I
I'm using ASP.Net MVC Design pattern and when adding a controller to my application
I've a problem with adding jQuery to an ASP.NET MVC application. I add jquery
In a ASP.Net MVC 2 application I want to do the following: in the
I am adding ASP.NET MVC to an existing WebForms application. For the time being,
When adding the StructureMap-MVC3 package to an ASP.NET MVC application, an IoC class containing

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.