Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #24837

Re: Dynamically inserting script elements

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Dynamically inserting script elements
Date 2014-06-14 21:43 +0200
Organization PointedEars Software (PES)
Message-ID <2026431.rsCDfxh4iT@PointedEars.de> (permalink)
References <q3chp9p46ron6497svevkvlurllkeh26ci@4ax.com> <c7kip95ijtb9k8v58ka90k02396g5e6fpv@4ax.com> <XnsA34A68D747DAEeejj99@194.109.133.133> <539c706d$0$6607$9b4e6d93@newsspool4.arcor-online.net>

Show all headers | View raw


Christoph Michael Becker wrote:

> I don't know if there is any standard specification of the behavior, but
> a quick test on current stable Chrome required to insert the script
> element into the DOM before the script was loaded.

There is something close that specifies exactly this behavior:

<http://www.w3.org/TR/2014/CR-html5-20140204/scripting-1.html#the-script-element>

I think it is only logical that the script element resource would not be 
parsed before it is inserted because a client-side script may depend on 
symbols defined in other scripts that may need to be included dynamically as 
well.

However, it should be noted that loading script elements this way is 
asynchronous: you cannot assume that the symbols in the loaded script are 
immediately available afterwards.  It is therefore good that HTML5 CR also 
specifies events like “beforescriptexecute”, “afterscriptexecute” and, most 
notably, “load”, for the “script” element.  It would appear that, finally, 
there is going to be a standards-compliant way to load script resources 
dynamically without resorting to hacks and XHR.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

strange splits Roedy Green <see_website@mindprod.com.invalid> - 2014-06-11 12:41 -0700
  Re: strange splits John C <rescattered@gmail.com> - 2014-06-11 13:06 -0700
  Re: strange splits Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2014-06-12 09:05 +0200
    Re: strange splits "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-12 10:18 +0200
      Dynamically inserting script elements (was: strange splits) Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-14 17:55 +0200
        Re: Dynamically inserting script elements Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-14 21:43 +0200
          Re: Dynamically inserting script elements Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-16 19:36 +0200
    Re: strange splits John Harris <niam@jghnorth.org.uk.invalid> - 2014-06-12 11:49 +0100

csiph-web