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

The Archive Base Latest Questions

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

The context: My question relates to improving web-page loading performance, and in particular the

  • 0

The context: My question relates to improving web-page loading performance, and in particular the effect that javascript has on page-loading (resources/elements below the script are blocked from downloading/rendering).

This problem is usually avoided/mitigated by placing the scripts at the bottom (eg, just before the tag).

The code i am looking at is for web analytics. Placing it at the bottom reduces its accuracy; and because this script has no effect on the page’s content, ie, it’s not re-writing any part of the page–i want to move it inside the head. Just how to do that without ruining page-loading performance is the crux.

From my research, i’ve found six techniques (w/ support among all or most of the major browsers) for downloading scripts so that they don’t block down-page content from loading/rendering:

(i) XHR + eval();

(ii) XHR + inject;

(iii) download the HTML-wrapped script as in iFrame;

(iv) setting the script tag’s async flag to TRUE (HTML 5 only);

(v) setting the script tag’s defer attribute; and

(vi) ‘Script DOM Element’.

It’s the last of these i don’t understand. The javascript to implement the pattern (vi) is:

(function() {
  var q1 = document.createElement('script');
  q1.src = 'http://www.my_site.com/q1.js'
  document.documentElement.firstChild.appendChild(q1)
})();

Seems simple enough: and anonymous function is created then executed in the same block. Inside this anonymous function:

  • a script element is created

  • its src element is set to it’s location, then

  • the script element is added to the DOM

But while each line is clear, it’s still not clear to me how exactly this pattern allows script loading without blocking down-page elements/resources from rendering/loading?

  • 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-14T07:06:30+00:00Added an answer on May 14, 2026 at 7:06 am

    One note first:

    (iv) setting the script tag’s ‘async’ flag to ‘TRUE’ (HTML 5 only);

    async is a “boolean attribute”, in the HTML sense. That means that either of the following is correct:

    <script async src="..."></script>
    <script async="" src="..."></script>
    <script async="async" src="..."></script>
    

    And that both of the following make the script be loaded asynchronously, but are not conforming (because of the possible confusion):

    <script async="true" src="..."></script>
    <script async="false" src="..."></script>
    

    Now on your question. The point is that it is the HTML parser that is being blocked by the script (because people do stupid things things like document.write("<!--"), even from external JS files, and expect it to “work”). However, in your case (vi), the HTML parser doesn’t ever see the script element, because it is added to the DOM directly. Somewhat logically, if a script element (or rather, a <script> start tag) isn’t seen by the HTML parser, it can’t stop the parsing either.

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

Sidebar

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.