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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:56:45+00:00 2026-05-31T15:56:45+00:00

I’ve tried many different ways to phrase this question to google et al with

  • 0

I’ve tried many different ways to phrase this question to google et al with no luck. Not even sure the title of this question captures the nuance of the issue. I’ll try to explain then show the experiment. I hope someone(s) will be able to point to some explanation of what’s going on.

Given:

  • before the end of BODY, you have a script (A) that programmatically inserts a script element (using my preferred technique, document.createElement) into the document which references a remote-script (B)
  • remote-script B performs a document.write of any content (e.g. “hello, world”)
  • before the end of BODY and just after script A you have a script (C) that references a remote-script which takes a while to load (e.g. 1s)

What will happen is that A executes, inserts B into the document and starts to download the resource. While B is downloading, C will execute and wait, because of the delay. While C is waiting, B is downloaded and executes; we have not yet hit DOMContentLoaded; document.readyState is still “loading”. The document.write from B is ignored; gobbled up, as if we are post-DOMContentLoaded. C then finishes downloading and executes.

Experiment:

  • Source: http://jsfiddle.net/jaknowlden/pwHG8/
  • Try it out directly: http://jsfiddle.net/jaknowlden/pwHG8/show/
  • Waterfall: MANUAL LINK[cl.ly/423P2M1d0r0e0k3h370g]
  • Remote script: MANUAL LINK[thumblemonks.com/js/stackoverflow-script-b.js]

I am using Cuzillion to create the delay. If you check out the waterfall image, you’ll also see the console.log message, which shows that everything is executed before the DOM hits “interactive” readyState (i.e. DOMContentLoaded).

What I expect as output in the browser is:

TOP
hello, world
hello again, world
BOTTOM

What I get as output is:

TOP
hello, world
BOTTOM

You’ll notice in my experiment that I have added another script between what we would define as A and C. Call this A’ I suppose; it shows that if you dynamically add a script that has text (i.e. not a remote script) which contains a document.write, the doc.write in A’ WILL work.

Also, dummy.js and the CSS files come from JSFiddle. They are not the culprits; I can recreate this issue anywhere.

Things I know:

  • if you replace C with an IMG, there is no issue
  • if you replace C with an IFRAME, there is no issue
  • if you move A after C, there is no issue

Now:

Perhaps there is a perfectly valid reason for this. There must be since all of the browsers I’ve tested in seem to behave in roughly the same way. What I’d like to know is why? Any explanations, hints, and/or pointers are welcome. Even hints like “It’s in the spec, dumby :)” I’ve got thick skin; I can handle it.

DISCLAIMER: I abhor document.write. My intention is not to support or bolster its use in any way. However, given the nature of my work, I have to work around it for now and this oddity sprung itself on me. Thus, I’d like to avoid comments along the line of “you shouldn’t use document.write” because this, I already believe in 🙂

  • 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-31T15:56:46+00:00Added an answer on May 31, 2026 at 3:56 pm

    Doing document.write from async-loaded scripts is not supported in HTML5, precisely because it’s racy: you have no way to know whether your script will run before or after DOMContentLoaded. See http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#ignore-destructive-writes-counter and http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#dom-document-write step 2 and http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#execute-the-script-block step 3. The point being that having the write work if the script beats the race to DOMContentLoaded but be ignored if it loses the race would be pretty odd and would lead to pages sometimes working and sometimes not depending on network conditions.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

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.