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 8279397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:19:31+00:00 2026-06-08T09:19:31+00:00

I have the issue of loading the same scripts across all my pages without

  • 0

I have the issue of loading the same scripts across all my pages without having to define them all over and over.

I’ve came up with a half complete solution which looks like…

var scriptLocs = [];

function loadScripts() {
    for (var i = 0; i < scriptLocs.length; i++) {
        var crtElement = document.createElement('script');
        crtElement.src = scriptLocs[i];
        var hh = document.getElementsByTagName('head')[0];
        // Getting head tag
        hh.appendChild(crtElement);
        //Adding it to head
    }
}​

The array can be very big e.g. around 120 scripts (2.5MB) these include such things as jQuery and Knockout etc…

The problem im having is this can be unreliable my function seems to miss out, or load in a different order than defined in my array. The order is very important as some things may rely on jQuery so it must be loaded before other scripts.

Also its differnt errors on every refresh … E.g. maybe differnt loading order?

Is there away of define all the scripts in an element then appending the lot of them at once? would this work?

UPDATE:

Using this test.js file

for (var i = 0; i < scriptLocs.length; i++) {
    document.write("<script type=\"text/javascript\" src=\"" + scriptLocs[i] + "\"><\/script>");
}

And including it as the very first thing in the head like..

<!DOCTYPE HTML>
<html>
    <head>
        <title>Test</title>

        <meta name="viewport" content="width=device-width, initial-scale=1">

        <script type="text/javascript" src="test.js"></script>

Seems to solve this problem

  • 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-08T09:19:32+00:00Added an answer on June 8, 2026 at 9:19 am

    This is what document.write() is for. Frequently it is misused, but in this case, it’s a good choice:

    var scriptLocs = [...];
    for (var i = 0; i < scriptLocs.length; i++) {
        document.write("<script type=\"text/javascript\" src=\""+scriptLocs[i]+"\"><\/script>");
    }
    

    But do not put this in a function or call it from an event handler. This script should run immediately while the page is loading. Calling document.write() after the dom has loaded causes problems.

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

Sidebar

Related Questions

I am having issue with loading test.xml and test.properties inside the same folder conf.
I have an issue which I could not find answer for across the web.
I have an issue where the JavaScript source file is loading in popup for
I am having a strange issue in my flex app. I have a Video
I'm having a problem.. Actually I do have an issue when sending a value
Hi I have come up with a small design but im having one issue
I'm having an odd situation where I am getting a lazy loading issue on
All of a sudden, I have run into an issue where I cannot step
I have issue with: <form:checkboxes path=roles cssClass=checkbox items=${roleSelections} /> If previous line is used
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So

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.