<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.whatwg.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Serverherder</id>
	<title>WHATWG Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.whatwg.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Serverherder"/>
	<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/wiki/Special:Contributions/Serverherder"/>
	<updated>2026-05-14T04:39:02Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5727</id>
		<title>Talk:Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5727"/>
		<updated>2011-01-03T15:05:46Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* response */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please discuss the proposal here. All informal feedback is welcomed, and when it&#039;s appropriate, please add content to the main page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What about CommonJS / RequireJS? ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m not sure we need to complicate the HTML or browser engines in order to satisfy the advanced use cases.  To me it seems that the JavaScript langauge itself could abstract the requirements and let the browser vendors implement whatever solution they see fit.  Specifically, if JavaScript provided the define() and require() calls proposed in the CommonJS &amp;quot;specifications&amp;quot; (and implemented by [http://requirejs.org/docs/api.html RequireJS], [http://svn.dojotoolkit.org/src/dojo/trunk/_base/_loader/loader.js dojo (trunk)], and others *Yabble?), then browsers could just load and evaluate scripts as fast as possible without regard to script execution order.  &lt;br /&gt;
&lt;br /&gt;
This would solve all of the problems except for the current inability to use loaders like LABjs in FF4 or webkit.  To solve that problem, we should consider keeping the existing functionality or triggering the deprecated functionality when needed.&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
=== Response ===&lt;br /&gt;
&lt;br /&gt;
This is a valid point except that it assumes that all code that needs to be loaded is &amp;quot;modular&amp;quot;... in fact, most code on the internet that needs to be loaded is NOT modular, and instead requires particular ordering when being loaded... for instance, &amp;quot;jquery&amp;quot; and &amp;quot;jquery-ui&amp;quot; -- jQuery must be run before jQuery-UI is loaded and run.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The spirit of this proposal is to add the facility to native browser (rendering engine, specifically) behavior, such that any and all existing content is able to be loaded (even with dependencies and order) without modification.&lt;br /&gt;
&amp;lt;blockquote style=background-color:#eee&amp;gt;&lt;br /&gt;
Are we trying to codify how one would implement this HTML dynamically so I can achieve parallel loading but retain dependency that is inferred in the order? &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: white&amp;quot;&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery-ui.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If so, we must consider the case in which the dependency itself loads additional code which the discussions around `async=false` or even text/cache do not account for.  &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:23, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dependent code should be modular ===&lt;br /&gt;
&lt;br /&gt;
I completely agree, 99% of JavaScript in use today is NOT modular, but that&#039;s arguably because there was no built-in support to make it modular (IMHO, YMMV, RTFM, BBQ, ROFL).  But that doesn&#039;t mean there aren&#039;t dependencies that span script files / script nodes.  I don&#039;t know how many sites would be broken (or if there is any way to determine how many sites would be broken) if/when the latest browsers started loading and evaluating script-injected scripts out of order.  It&#039;s not just LABjs-based sites.  I&#039;ll bet many dojo and YUI sites will break, too (although I don&#039;t know this for a fact because I don&#039;t know exactly how their dynamic script loaders work).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;In any case, breaking existing sites is a BAD IDEA. :)  There should be some way to allow LABjs and other dynamic script loaders to continue to work.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The part I don&#039;t agree with in the proposals is that it should be the job of HTML and/or the browser engine to manage dependencies.  Specifically, I am talking about the scriptGroup element and the &amp;quot;waitFor&amp;quot; attribute.  The &amp;quot;async&amp;quot; attribute may be the right level: it appropriates only general heuristics to the browser: &#039;&#039;load these scripts whenever you like, but load these other scripts in this order&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Detailed dependency management belongs in the modules, though.  This is how it&#039;s done in most environments / languages: import statements, include statements, etc.  It&#039;s no different in JavaScript, if a developer wants to take advantage of some code in another module, she/he should import it into their current module.  This should be the model moving forward.  It&#039;s not hard, it&#039;s not un-web-like, and it&#039;s already being done.  &lt;br /&gt;
&lt;br /&gt;
Existing code can be made to work modularly, too:&lt;br /&gt;
&lt;br /&gt;
1. Identify modules and wrap them with a define() method.&lt;br /&gt;
2. Identify dependencies using either the [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition Asynchronous Module Definition] format or the CommonJS synchronous format&lt;br /&gt;
&lt;br /&gt;
async format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define([&#039;dependency1&#039;, &#039;dependency2&#039;], function (dependency1, dependency2) {&lt;br /&gt;
	/* this is the factory function, return the module inside here */&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sync format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define(function (require, exports, module) {&lt;br /&gt;
	/* this is the factory function, require dependencies and return the module inside here */&lt;br /&gt;
	var dependency1 = require(&#039;dependency1&#039;);&lt;br /&gt;
	var dependency2 = require(&#039;dependency2&#039;);&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the async case, the browser may employ whatever method it sees fit (e.g. parallel) to download the dependencies since the code inside the factory function won&#039;t execute until all of the dependencies are loaded and evaluated.  In the sync case, the browser has no choice but to download and evaluate the dependency before continuing code execution.  It&#039;s conceivable that the browser could find and asynchronously pre-fetch the inline require()&#039;ed dependencies in the sync case.  (RequireJS doesn&#039;t quite do this.  Instead I believe it finds the inline require() calls and converts the module to an async module.)  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;So, in short: don&#039;t break LABjs (or any other script loaders), but don&#039;t extend the spec to manage dependency management from HTML.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Response #2 ==&lt;br /&gt;
&lt;br /&gt;
The cat&#039;s already out of the bag... we&#039;ve got a dozen+ years worth, hundreds of millions of javascript files out there, which are NOT modular, and will not be modified to be modular. &lt;br /&gt;
&lt;br /&gt;
If we&#039;re talking about either trying to change all the JS on the web to be modular, or trying to extend the HTML markup spec to include a better facility for accomodating the existing script content, I think the former is idealistic and &amp;quot;correct&amp;quot; but the latter is realistic and &amp;quot;right&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
A modular loading system will only work for modular code, but a general loading mechanism in HTML (like the &amp;amp;lt;script&amp;gt; tag) can load both modular and non-modular code, which is why that more general mechanism is what&#039;s in HTML right now and not some more specialized loading API that only loads a small percentage of JavaScript code out there.&lt;br /&gt;
&lt;br /&gt;
The &amp;amp;lt;script&amp;gt; tag has worked fine forever, and there&#039;s been no real big push to do away with it in favor of having all loading handled by JavaScript -- in fact, that would be impossible because if you had no way to load JS onto the page with a &amp;amp;lt;script&amp;gt; tag, then no JavaScript could run on a page to load more code. So I don&#039;t agree that we should stop adding functionality to the HTML loading mechanism and only focus on JavaScript.&lt;br /&gt;
&lt;br /&gt;
If we agree that the &amp;amp;lt;script&amp;gt; tag itself is not only required but normative, then I&#039;m not sure why decorating the &amp;amp;lt;script&amp;gt; tag with additional behavior to help it be more powerful is a bad pattern. We&#039;ve addded &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; already. I&#039;m not sure I understand why adding a wrapper tag called &amp;quot;scriptGroup&amp;quot; would be that much different than attributes on the &amp;amp;lt;script&amp;gt; tag?&lt;br /&gt;
&lt;br /&gt;
I also don&#039;t think that &amp;quot;scriptGroup&amp;quot; constitutes &amp;quot;dependency management&amp;quot;. &amp;quot;scriptGroup&amp;quot; is a semantic way for a web author to express that they want to group a set of scripts together ONLY so far as execution order behavior is concerned. It implies nothing more to it (that &amp;quot;dependency management&amp;quot; would imply) than that.&lt;br /&gt;
&lt;br /&gt;
For instance, consider this: if JavaScript had been built with non-global context and statement level context and sandboxing and such things, we&#039;d have a much more secure JavaScript right now. But just because JavaScript may someday be taught some new tricks in terms of security, that doesn&#039;t mean that &amp;quot;now&amp;quot; HTML shouldn&#039;t try to help solve the problem. If for instance the &amp;amp;lt;frag&amp;gt; tag can be used to create a sandboxed environment for third-party JavaScript code to run in, this is a much easier way to address the security problem than to suggest we have to wait for ES-Harmony to add extra syntax to the language to accomplish the same thing.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 02:13, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Text/cache solution ==&lt;br /&gt;
&lt;br /&gt;
It seems to me that having a real text/cache script type, or a similar element that fires a load/error event and provides a .text property gets you where you need to be. You could setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/JavaScript&amp;quot;) or use the text to create a new script element. Or a new style element, or whatever. That puts you in control of when script or CSS is interpreted. With async as the default, you don&#039;t need a new ordered attribute as that&#039;s easily managed in script.&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;text/cache&amp;quot; response ==&lt;br /&gt;
&lt;br /&gt;
On the surface, this idea sounds like it&#039;s pretty similar to &amp;amp;lt;link rel=prefetch&amp;gt; -- in other words, we&#039;ve already standardized a way to prefetch a resource into cache, and probably in a better way than the hack that I did in LABjs of just relying on it fetching unrecognizable content.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it still suffers some similar problems to &amp;amp;lt;link rel=prefetch&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Firstly, if the notion is that you&#039;d use &amp;amp;lt;script type=&amp;quot;text/cache&amp;quot;&amp;gt; to prefetch, and then you&#039;d make a second request for the resource with a real &amp;amp;lt;script type=&amp;quot;text/javascript&amp;gt; node, it suffers the faulty assumption that the resource was served with proper cache headers.&lt;br /&gt;
&lt;br /&gt;
If we try to avoid the need for the second request by suggesting that you can access the `text` property of the node (and then eval() or inject that code when you want to execute it), this runs afoul of the same-origin policy problem if you requested the script from a non-local domain.&lt;br /&gt;
&lt;br /&gt;
The part of your suggestion that holds water would be if, given a &amp;quot;prefetched&amp;quot; script node that didn&#039;t execute yet, I could simply change that node&#039;s `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;, and that would explicitly trigger the browser to immediately execute it. &lt;br /&gt;
&lt;br /&gt;
This is an interesting idea. I can see though that it perhaps has some potential complications. &lt;br /&gt;
&lt;br /&gt;
For instance, would the browser have to keep a &amp;quot;hasExecuted&amp;quot; internal flag, so that changing the `type` value would only at most result in one execution? Also, if the script node in question is loaded but not executed, can the page alter the script code (by setting its `text` property) before making the change to the `type` value? In that case, should the browser execute the original code or the modified code? I can see security implications and confusion abounding in that behavior.&lt;br /&gt;
&lt;br /&gt;
Lastly, as mentioned above, this basically copies (in a similar but not exactly identical way) the &amp;amp;lt;link rel=prefetch&amp;gt; behavior. It may be seen as a negative to be trying to step on the toes of &amp;amp;lt;link rel=prefetch&amp;gt;, and also it may be more confusing to the general public as to why you&#039;d use one technique or the other, given their differences being so nuanced.&lt;br /&gt;
&lt;br /&gt;
That having been said, I can see that it&#039;s a viable alternate proposal. It&#039;s worth adding a note to that section of the main Wiki page and to getting some feedback from browser vendors on if they feel this is a more realistic/suitable solution to the use-case.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #eee&amp;quot;&amp;gt;&lt;br /&gt;
The difference between pre-fetching and this proposal seems pretty clear: Prefetching, if not performed now, will eventually be done once the user explicitly requests the page. while the &amp;quot;text/cache&amp;quot; solution indicates that the resource should load &#039;&#039;&#039;immediately&#039;&#039;&#039;, not during idle time. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:10, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 20:56, 4 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== RequireJS order support ==&lt;br /&gt;
&lt;br /&gt;
I am the main developer for RequireJS, and just want to voice my support for a solution that works on the script element itself, either by leveraging the async attribute or allowing something like an &amp;quot;order&amp;quot; boolean attribute that would allow specifying a dynamically added script element should be executed in the order that it appears in the DOM. This capability should be something can be capability detected to avoid browser sniffing.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Why shouldn&#039;t dependency management be implemented in high-level code and the browser simply provide a means by which parallel loading can be achieved?  As you know, there is a considerable amount of nuance.  I&#039;m of the opinion that implementing dependency management in the engine will eventually lead us right back to where we were 10 years ago with inline script tags which provides an easy method for dependency management at the expense of unmanaged blocking and an inability to detect or adapt to errors. &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
There are many scripts on the web today that have implicit dependencies that should be loaded in a specific order, but the application developer will want to use dynamically created script elements for best performance. jQuery plugins that depend on the jQuery script already been executed in the page are a good example.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Agreed, but I don&#039;t believe the proposals allow for proper emulation of the dependency management provided by script tags.  Prototype.js, for example, loads its core modules dynamically (using document.write so maybe not the best example...).  When prototype.js is included via script tags, ensuing script blocks are free to &amp;quot;depend&amp;quot; on all of these modules; Dynamically creating a dependency on prototype.js by loading both with the `async=true` property will fail since prototype.js won&#039;t be able to &amp;quot;jump the queue&amp;quot; and add insure its core modules load before its extensions.  &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#ccc&amp;quot;&amp;gt;&lt;br /&gt;
I have to admit, you raise a valid point with respect to that common usage. The YUI model (where the framework is responsible for all loading) is perhaps the more appropriate model to move toward, though. Or, the framework doesn&#039;t auto-load its own dependencies at all. In either case, I think it&#039;s cleaner to have one loading mechanism in play rather than two or more competing ones, because as you point out, this is going to get messy. I still am not sure this means that the async=false proposal is lacking, because as I think about how complicated such a split loading would be with your `readyState` proposal, that seems even worse/more complicated to me. [[User:Getify|Getify]] 20:06, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
I would not argue &#039;&#039;&#039;against&#039;&#039;&#039; a global queue for synchronized execution, I just think the usefulness of such a construct declines as scripts that &amp;quot;I don&#039;t care about&amp;quot; are added.  It&#039;s my opinion the spec should provide the ability for high-level code to implement similar constructs, regardless of how complex it may be to do so. &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
That being said, I don&#039;t think it&#039;s any more complicated than existing models.  Here&#039;s a demonstration of an [http://digital-fulcrum.com/executionorder/ IE-only parallel-loading, synchronously-executing script queue] implemented in 40 lines of code.  It tests both cached and un-cached scripts (from the LABjs test suite) and has been tested and found to be working in IE6-8. &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[User:Serverherder|Serverherder]] 01:52, 16 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
- James Burke&lt;br /&gt;
&lt;br /&gt;
== Vendors Should Implement the Existing Suggestion ==&lt;br /&gt;
&lt;br /&gt;
Since the spec all ready includes a suggestion to download resources when the SRC attribute is set, parallel loading is an option the &#039;&#039;&#039;vendor&#039;&#039;&#039; chooses to implement and not something a script loader should be able to require.  Vendors that don&#039;t implement the suggestion will run the risk of being less performant in these situations.  That, however, is &#039;&#039;&#039;their&#039;&#039;&#039; choice to make as the spec suggests.  If the benefits of parallel loading dependencies are so great, users will opt for this in their choice of agent or vendors can adopt the existing mechanism.&lt;br /&gt;
&lt;br /&gt;
== The Current Suggestion Should be Changed to a Mandate ==&lt;br /&gt;
&lt;br /&gt;
The spec is pretty clear on why it chose to make this optional.  If dependent script loading is so common that browsers that adopt the suggestion enjoy considerably better performance, the user will eventually decide to opt for those implementations.  On the other hand, if it is more common that scripts are created and never inserted, leading to wasted bandwidth and clogged fetching queues, the converse will occur.  Either way, by making it optional, the spec hedges its bet and is more prone to be future-proof as the habits of script developers evolve.&lt;br /&gt;
&lt;br /&gt;
== Modify the specification so parallel-loading is configurable  ==&lt;br /&gt;
The specification expresses the reasons parallel loading should not be done.  To this point, allowing developers a means to &#039;&#039;&#039;require&#039;&#039;&#039; resources be downloaded in parallel is in direct opposition to the spec&#039;s all ready stated position.  To this end, I see no purpose for async=true: A browser that hopes to be highly performant should implement the spec&#039;s suggestion to improve performance.  Developers should not be able to circumvent the vendor&#039;s attempt to be conservative in its use of bandwidth simply to achieve ordered execution.&lt;br /&gt;
&lt;br /&gt;
=== response ===&lt;br /&gt;
Nothing about this proposal requires any parallelism that the browser wouldn&#039;t already afford. The spirit of this proposal is not about loading behavior, but about execution order.&lt;br /&gt;
&lt;br /&gt;
The spec says nothing about the parallel loading, nor do I think it should necessarily. All modern browsers HAVE in fact implemented parallel loading for all scripts, regardless of async or not. And I think this is a good thing. But it has nothing to do with `async` or my proposal to make the definition of `async` symmetric/consistent between markup script elements and dynamic script elements.&lt;br /&gt;
&lt;br /&gt;
The spec already defines that `async` is specifically to create unblocking of the page&#039;s resource loading AND &amp;quot;as soon as possible&amp;quot; execution of the script. But it only defines this for parser-inserted (markup) script tags. I think this is short-sighted, because I think a script-loader should be able to opt into either ordered or unordered execution in the same way that markup script elements can. That&#039;s really all the main proposal is about.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#EEE&amp;quot;&amp;gt;&lt;br /&gt;
Script loaders can all ready choose ordered execution: chain the onload events.  The issue is that vendors have chosen &#039;&#039;&#039;not&#039;&#039;&#039; to adopt the specification&#039;s suggestion. The high priority vendors place on performance suggests this was not done consciously.  Instead of advocating WHATWG for additions to the spec, I think we may be better off advocating vendors implement the spec&#039;s suggestion.  The existing implementation of parallelism for parser-inserted scripts suggests vendors would be willing to do so and the existing lack of support is merely an issue of communication.  &lt;br /&gt;
&lt;br /&gt;
At its core, the existing suggestion to retrieve upon src assignment is not altogether different than the eager-fetching performed for parser-inserted scripts.  The risk still exists that the browser download a script that is never actually executed.  For example, below a bunch of script tags, the HTML may contain a closing comment tag (--&amp;gt;) and one of the scripts doc.write(&amp;quot;&amp;lt;\!--&amp;quot;).  Another risk is that the eager-fetching clog the fetch queue, delaying the download of any scripts included via document.write().    Vendors have &#039;&#039;&#039;chosen&#039;&#039;&#039; to assume this risk though, since its probability is low and the benefit high.  &lt;br /&gt;
&lt;br /&gt;
Likewise, vendors can calculate the risk/reward for script-inserted scripts and will likely make the same decision -- they implement this exact behavior for images.  Script loaders should respect the fact that a vendor has consciously chosen &#039;&#039;&#039;not&#039;&#039;&#039; to support parallelism for script-inserted scripts.  Providing a means by which this decision can be circumvented undermines their choice.   I believe it was in that spirit the specification leaves eager fetching script resources as a suggestion.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#ccc&amp;quot;&amp;gt;&lt;br /&gt;
I think you still miss the pragmatic point here. I&#039;m not disagreeing with you in theory, but in practice, the hard-nosed approach you suggest would spell death for any script loader. That&#039;s not a chance I&#039;m willing to take.&lt;br /&gt;
&lt;br /&gt;
When a developer uses a script loader that claims it is &amp;quot;The Performance Script Loader&amp;quot; (as LABjs does), and they test in some latest-version browser (whether that be FF, Safari, Chrome, IE, or Opera) and the performance is terrible (worse than before they installed LABjs), they&#039;re not going to say, &amp;quot;Well, I&#039;ll just keep LABjs in there and hope those browsers fix this quickly&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
This is tail-wagging-the-dog mentality, and it ignores the reality: people will almost always chose the path of least resistance. If they try a script loader, and it gives them worse performance than before, they&#039;ll simply take it out. They may complain about it once in a tweet, but they won&#039;t take a stand against the browsers to the detriment of their own site and their own users, and they won&#039;t tell all their users to switch to another browser in protest.&lt;br /&gt;
&lt;br /&gt;
And worse, for LABjs, the path of least resistance may very well mean that if performance is important to them, they&#039;ll just pick some other loader, which has more hacks in it. As long as they get what they want, which is reliable and pretty good performance, they&#039;ll be happy. And it will totally have been lost on them that the battle for web standards was just dealt a blow by their actions. General web page authors do not care to fight that battle on behalf of LABjs. So, LABjs must fight that battle under the covers.&lt;br /&gt;
&lt;br /&gt;
I understand your perspective, but I can say as the maintainer of a tool like LABjs that cares about keeping its relevancy for &amp;quot;survival&amp;quot;, I won&#039;t take an action that I know is likely to cause a decline in the usefulness of my tool. Instead, I will take a more cautious, slow-to-change approach, while at the same time feature-testing for the new standards and using them if available. Only after a long time of the new feature-testable stuff being present will I consider removing the legacy stuff. This is a strategy I think almost every framework/lib maintainer would echo support for.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 00:50, 24 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 21:39, 23 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: white&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt; A phased approach toward adopting this is reasonable and you clearly state the risks of both positions.  My comments have derailed the true purpose of this discussion: &#039;&#039;Does the specification require modification&#039;&#039;?  Since the spec all ready provides a mechanism by which this functionality can be achieved, I believe it is best to reword the suggestion so it more appropriately conveys the importance of it, but don&#039;t think the behavior should be imposed on vendors.  &lt;br /&gt;
[[User:Serverherder|Serverherder]]&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5675</id>
		<title>Talk:Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5675"/>
		<updated>2010-12-23T22:58:18Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* response */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please discuss the proposal here. All informal feedback is welcomed, and when it&#039;s appropriate, please add content to the main page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What about CommonJS / RequireJS? ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m not sure we need to complicate the HTML or browser engines in order to satisfy the advanced use cases.  To me it seems that the JavaScript langauge itself could abstract the requirements and let the browser vendors implement whatever solution they see fit.  Specifically, if JavaScript provided the define() and require() calls proposed in the CommonJS &amp;quot;specifications&amp;quot; (and implemented by [http://requirejs.org/docs/api.html RequireJS], [http://svn.dojotoolkit.org/src/dojo/trunk/_base/_loader/loader.js dojo (trunk)], and others *Yabble?), then browsers could just load and evaluate scripts as fast as possible without regard to script execution order.  &lt;br /&gt;
&lt;br /&gt;
This would solve all of the problems except for the current inability to use loaders like LABjs in FF4 or webkit.  To solve that problem, we should consider keeping the existing functionality or triggering the deprecated functionality when needed.&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
=== Response ===&lt;br /&gt;
&lt;br /&gt;
This is a valid point except that it assumes that all code that needs to be loaded is &amp;quot;modular&amp;quot;... in fact, most code on the internet that needs to be loaded is NOT modular, and instead requires particular ordering when being loaded... for instance, &amp;quot;jquery&amp;quot; and &amp;quot;jquery-ui&amp;quot; -- jQuery must be run before jQuery-UI is loaded and run.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The spirit of this proposal is to add the facility to native browser (rendering engine, specifically) behavior, such that any and all existing content is able to be loaded (even with dependencies and order) without modification.&lt;br /&gt;
&amp;lt;blockquote style=background-color:#eee&amp;gt;&lt;br /&gt;
Are we trying to codify how one would implement this HTML dynamically so I can achieve parallel loading but retain dependency that is inferred in the order? &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: white&amp;quot;&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery-ui.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If so, we must consider the case in which the dependency itself loads additional code which the discussions around `async=false` or even text/cache do not account for.  &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:23, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dependent code should be modular ===&lt;br /&gt;
&lt;br /&gt;
I completely agree, 99% of JavaScript in use today is NOT modular, but that&#039;s arguably because there was no built-in support to make it modular (IMHO, YMMV, RTFM, BBQ, ROFL).  But that doesn&#039;t mean there aren&#039;t dependencies that span script files / script nodes.  I don&#039;t know how many sites would be broken (or if there is any way to determine how many sites would be broken) if/when the latest browsers started loading and evaluating script-injected scripts out of order.  It&#039;s not just LABjs-based sites.  I&#039;ll bet many dojo and YUI sites will break, too (although I don&#039;t know this for a fact because I don&#039;t know exactly how their dynamic script loaders work).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;In any case, breaking existing sites is a BAD IDEA. :)  There should be some way to allow LABjs and other dynamic script loaders to continue to work.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The part I don&#039;t agree with in the proposals is that it should be the job of HTML and/or the browser engine to manage dependencies.  Specifically, I am talking about the scriptGroup element and the &amp;quot;waitFor&amp;quot; attribute.  The &amp;quot;async&amp;quot; attribute may be the right level: it appropriates only general heuristics to the browser: &#039;&#039;load these scripts whenever you like, but load these other scripts in this order&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Detailed dependency management belongs in the modules, though.  This is how it&#039;s done in most environments / languages: import statements, include statements, etc.  It&#039;s no different in JavaScript, if a developer wants to take advantage of some code in another module, she/he should import it into their current module.  This should be the model moving forward.  It&#039;s not hard, it&#039;s not un-web-like, and it&#039;s already being done.  &lt;br /&gt;
&lt;br /&gt;
Existing code can be made to work modularly, too:&lt;br /&gt;
&lt;br /&gt;
1. Identify modules and wrap them with a define() method.&lt;br /&gt;
2. Identify dependencies using either the [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition Asynchronous Module Definition] format or the CommonJS synchronous format&lt;br /&gt;
&lt;br /&gt;
async format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define([&#039;dependency1&#039;, &#039;dependency2&#039;], function (dependency1, dependency2) {&lt;br /&gt;
	/* this is the factory function, return the module inside here */&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sync format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define(function (require, exports, module) {&lt;br /&gt;
	/* this is the factory function, require dependencies and return the module inside here */&lt;br /&gt;
	var dependency1 = require(&#039;dependency1&#039;);&lt;br /&gt;
	var dependency2 = require(&#039;dependency2&#039;);&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the async case, the browser may employ whatever method it sees fit (e.g. parallel) to download the dependencies since the code inside the factory function won&#039;t execute until all of the dependencies are loaded and evaluated.  In the sync case, the browser has no choice but to download and evaluate the dependency before continuing code execution.  It&#039;s conceivable that the browser could find and asynchronously pre-fetch the inline require()&#039;ed dependencies in the sync case.  (RequireJS doesn&#039;t quite do this.  Instead I believe it finds the inline require() calls and converts the module to an async module.)  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;So, in short: don&#039;t break LABjs (or any other script loaders), but don&#039;t extend the spec to manage dependency management from HTML.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Response #2 ==&lt;br /&gt;
&lt;br /&gt;
The cat&#039;s already out of the bag... we&#039;ve got a dozen+ years worth, hundreds of millions of javascript files out there, which are NOT modular, and will not be modified to be modular. &lt;br /&gt;
&lt;br /&gt;
If we&#039;re talking about either trying to change all the JS on the web to be modular, or trying to extend the HTML markup spec to include a better facility for accomodating the existing script content, I think the former is idealistic and &amp;quot;correct&amp;quot; but the latter is realistic and &amp;quot;right&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
A modular loading system will only work for modular code, but a general loading mechanism in HTML (like the &amp;amp;lt;script&amp;gt; tag) can load both modular and non-modular code, which is why that more general mechanism is what&#039;s in HTML right now and not some more specialized loading API that only loads a small percentage of JavaScript code out there.&lt;br /&gt;
&lt;br /&gt;
The &amp;amp;lt;script&amp;gt; tag has worked fine forever, and there&#039;s been no real big push to do away with it in favor of having all loading handled by JavaScript -- in fact, that would be impossible because if you had no way to load JS onto the page with a &amp;amp;lt;script&amp;gt; tag, then no JavaScript could run on a page to load more code. So I don&#039;t agree that we should stop adding functionality to the HTML loading mechanism and only focus on JavaScript.&lt;br /&gt;
&lt;br /&gt;
If we agree that the &amp;amp;lt;script&amp;gt; tag itself is not only required but normative, then I&#039;m not sure why decorating the &amp;amp;lt;script&amp;gt; tag with additional behavior to help it be more powerful is a bad pattern. We&#039;ve addded &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; already. I&#039;m not sure I understand why adding a wrapper tag called &amp;quot;scriptGroup&amp;quot; would be that much different than attributes on the &amp;amp;lt;script&amp;gt; tag?&lt;br /&gt;
&lt;br /&gt;
I also don&#039;t think that &amp;quot;scriptGroup&amp;quot; constitutes &amp;quot;dependency management&amp;quot;. &amp;quot;scriptGroup&amp;quot; is a semantic way for a web author to express that they want to group a set of scripts together ONLY so far as execution order behavior is concerned. It implies nothing more to it (that &amp;quot;dependency management&amp;quot; would imply) than that.&lt;br /&gt;
&lt;br /&gt;
For instance, consider this: if JavaScript had been built with non-global context and statement level context and sandboxing and such things, we&#039;d have a much more secure JavaScript right now. But just because JavaScript may someday be taught some new tricks in terms of security, that doesn&#039;t mean that &amp;quot;now&amp;quot; HTML shouldn&#039;t try to help solve the problem. If for instance the &amp;amp;lt;frag&amp;gt; tag can be used to create a sandboxed environment for third-party JavaScript code to run in, this is a much easier way to address the security problem than to suggest we have to wait for ES-Harmony to add extra syntax to the language to accomplish the same thing.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 02:13, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Text/cache solution ==&lt;br /&gt;
&lt;br /&gt;
It seems to me that having a real text/cache script type, or a similar element that fires a load/error event and provides a .text property gets you where you need to be. You could setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/JavaScript&amp;quot;) or use the text to create a new script element. Or a new style element, or whatever. That puts you in control of when script or CSS is interpreted. With async as the default, you don&#039;t need a new ordered attribute as that&#039;s easily managed in script.&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;text/cache&amp;quot; response ==&lt;br /&gt;
&lt;br /&gt;
On the surface, this idea sounds like it&#039;s pretty similar to &amp;amp;lt;link rel=prefetch&amp;gt; -- in other words, we&#039;ve already standardized a way to prefetch a resource into cache, and probably in a better way than the hack that I did in LABjs of just relying on it fetching unrecognizable content.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it still suffers some similar problems to &amp;amp;lt;link rel=prefetch&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Firstly, if the notion is that you&#039;d use &amp;amp;lt;script type=&amp;quot;text/cache&amp;quot;&amp;gt; to prefetch, and then you&#039;d make a second request for the resource with a real &amp;amp;lt;script type=&amp;quot;text/javascript&amp;gt; node, it suffers the faulty assumption that the resource was served with proper cache headers.&lt;br /&gt;
&lt;br /&gt;
If we try to avoid the need for the second request by suggesting that you can access the `text` property of the node (and then eval() or inject that code when you want to execute it), this runs afoul of the same-origin policy problem if you requested the script from a non-local domain.&lt;br /&gt;
&lt;br /&gt;
The part of your suggestion that holds water would be if, given a &amp;quot;prefetched&amp;quot; script node that didn&#039;t execute yet, I could simply change that node&#039;s `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;, and that would explicitly trigger the browser to immediately execute it. &lt;br /&gt;
&lt;br /&gt;
This is an interesting idea. I can see though that it perhaps has some potential complications. &lt;br /&gt;
&lt;br /&gt;
For instance, would the browser have to keep a &amp;quot;hasExecuted&amp;quot; internal flag, so that changing the `type` value would only at most result in one execution? Also, if the script node in question is loaded but not executed, can the page alter the script code (by setting its `text` property) before making the change to the `type` value? In that case, should the browser execute the original code or the modified code? I can see security implications and confusion abounding in that behavior.&lt;br /&gt;
&lt;br /&gt;
Lastly, as mentioned above, this basically copies (in a similar but not exactly identical way) the &amp;amp;lt;link rel=prefetch&amp;gt; behavior. It may be seen as a negative to be trying to step on the toes of &amp;amp;lt;link rel=prefetch&amp;gt;, and also it may be more confusing to the general public as to why you&#039;d use one technique or the other, given their differences being so nuanced.&lt;br /&gt;
&lt;br /&gt;
That having been said, I can see that it&#039;s a viable alternate proposal. It&#039;s worth adding a note to that section of the main Wiki page and to getting some feedback from browser vendors on if they feel this is a more realistic/suitable solution to the use-case.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #eee&amp;quot;&amp;gt;&lt;br /&gt;
The difference between pre-fetching and this proposal seems pretty clear: Prefetching, if not performed now, will eventually be done once the user explicitly requests the page. while the &amp;quot;text/cache&amp;quot; solution indicates that the resource should load &#039;&#039;&#039;immediately&#039;&#039;&#039;, not during idle time. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:10, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 20:56, 4 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== RequireJS order support ==&lt;br /&gt;
&lt;br /&gt;
I am the main developer for RequireJS, and just want to voice my support for a solution that works on the script element itself, either by leveraging the async attribute or allowing something like an &amp;quot;order&amp;quot; boolean attribute that would allow specifying a dynamically added script element should be executed in the order that it appears in the DOM. This capability should be something can be capability detected to avoid browser sniffing.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Why shouldn&#039;t dependency management be implemented in high-level code and the browser simply provide a means by which parallel loading can be achieved?  As you know, there is a considerable amount of nuance.  I&#039;m of the opinion that implementing dependency management in the engine will eventually lead us right back to where we were 10 years ago with inline script tags which provides an easy method for dependency management at the expense of unmanaged blocking and an inability to detect or adapt to errors. &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
There are many scripts on the web today that have implicit dependencies that should be loaded in a specific order, but the application developer will want to use dynamically created script elements for best performance. jQuery plugins that depend on the jQuery script already been executed in the page are a good example.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Agreed, but I don&#039;t believe the proposals allow for proper emulation of the dependency management provided by script tags.  Prototype.js, for example, loads its core modules dynamically (using document.write so maybe not the best example...).  When prototype.js is included via script tags, ensuing script blocks are free to &amp;quot;depend&amp;quot; on all of these modules; Dynamically creating a dependency on prototype.js by loading both with the `async=true` property will fail since prototype.js won&#039;t be able to &amp;quot;jump the queue&amp;quot; and add insure its core modules load before its extensions.  &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#ccc&amp;quot;&amp;gt;&lt;br /&gt;
I have to admit, you raise a valid point with respect to that common usage. The YUI model (where the framework is responsible for all loading) is perhaps the more appropriate model to move toward, though. Or, the framework doesn&#039;t auto-load its own dependencies at all. In either case, I think it&#039;s cleaner to have one loading mechanism in play rather than two or more competing ones, because as you point out, this is going to get messy. I still am not sure this means that the async=false proposal is lacking, because as I think about how complicated such a split loading would be with your `readyState` proposal, that seems even worse/more complicated to me. [[User:Getify|Getify]] 20:06, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
I would not argue &#039;&#039;&#039;against&#039;&#039;&#039; a global queue for synchronized execution, I just think the usefulness of such a construct declines as scripts that &amp;quot;I don&#039;t care about&amp;quot; are added.  It&#039;s my opinion the spec should provide the ability for high-level code to implement similar constructs, regardless of how complex it may be to do so. &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
That being said, I don&#039;t think it&#039;s any more complicated than existing models.  Here&#039;s a demonstration of an [http://digital-fulcrum.com/executionorder/ IE-only parallel-loading, synchronously-executing script queue] implemented in 40 lines of code.  It tests both cached and un-cached scripts (from the LABjs test suite) and has been tested and found to be working in IE6-8. &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[User:Serverherder|Serverherder]] 01:52, 16 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
- James Burke&lt;br /&gt;
&lt;br /&gt;
== Vendors Should Implement the Existing Suggestion ==&lt;br /&gt;
&lt;br /&gt;
Since the spec all ready includes a suggestion to download resources when the SRC attribute is set, parallel loading is an option the &#039;&#039;&#039;vendor&#039;&#039;&#039; chooses to implement and not something a script loader should be able to require.  Vendors that don&#039;t implement the suggestion will run the risk of being less performant in these situations.  That, however, is &#039;&#039;&#039;their&#039;&#039;&#039; choice to make as the spec suggests.  If the benefits of parallel loading dependencies are so great, users will opt for this in their choice of agent or vendors can adopt the existing mechanism.&lt;br /&gt;
&lt;br /&gt;
== The Current Suggestion Should be Changed to a Mandate ==&lt;br /&gt;
&lt;br /&gt;
The spec is pretty clear on why it chose to make this optional.  If dependent script loading is so common that browsers that adopt the suggestion enjoy considerably better performance, the user will eventually decide to opt for those implementations.  On the other hand, if it is more common that scripts are created and never inserted, leading to wasted bandwidth and clogged fetching queues, the converse will occur.  Either way, by making it optional, the spec hedges its bet and is more prone to be future-proof as the habits of script developers evolve.&lt;br /&gt;
&lt;br /&gt;
== Modify the specification so parallel-loading is configurable  ==&lt;br /&gt;
The specification expresses the reasons parallel loading should not be done.  To this point, allowing developers a means to &#039;&#039;&#039;require&#039;&#039;&#039; resources be downloaded in parallel is in direct opposition to the spec&#039;s all ready stated position.  To this end, I see no purpose for async=true: A browser that hopes to be highly performant should implement the spec&#039;s suggestion to improve performance.  Developers should not be able to circumvent the vendor&#039;s attempt to be conservative in its use of bandwidth simply to achieve ordered execution.&lt;br /&gt;
&lt;br /&gt;
=== response ===&lt;br /&gt;
Nothing about this proposal requires any parallelism that the browser wouldn&#039;t already afford. The spirit of this proposal is not about loading behavior, but about execution order.&lt;br /&gt;
&lt;br /&gt;
The spec says nothing about the parallel loading, nor do I think it should necessarily. All modern browsers HAVE in fact implemented parallel loading for all scripts, regardless of async or not. And I think this is a good thing. But it has nothing to do with `async` or my proposal to make the definition of `async` symmetric/consistent between markup script elements and dynamic script elements.&lt;br /&gt;
&lt;br /&gt;
The spec already defines that `async` is specifically to create unblocking of the page&#039;s resource loading AND &amp;quot;as soon as possible&amp;quot; execution of the script. But it only defines this for parser-inserted (markup) script tags. I think this is short-sighted, because I think a script-loader should be able to opt into either ordered or unordered execution in the same way that markup script elements can. That&#039;s really all the main proposal is about.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#EEE&amp;quot;&amp;gt;&lt;br /&gt;
Script loaders can all ready choose ordered execution: chain the onload events.  The issue is that vendors have chosen &#039;&#039;&#039;not&#039;&#039;&#039; to adopt the specification&#039;s suggestion. The high priority vendors place on performance suggests this was not done consciously.  Instead of advocating WHATWG for additions to the spec, I think we may be better off advocating vendors implement the spec&#039;s suggestion.  The existing implementation of parallelism for parser-inserted scripts suggests vendors would be willing to do so and the existing lack of support is merely an issue of communication.  &lt;br /&gt;
&lt;br /&gt;
At its core, the existing suggestion to retrieve upon src assignment is not altogether different than the eager-fetching performed for parser-inserted scripts.  The risk still exists that the browser download a script that is never actually executed.  For example, below a bunch of script tags, the HTML may contain a closing comment tag (--&amp;gt;) and one of the scripts doc.write(&amp;quot;&amp;lt;!--&amp;quot;).  Another risk is that the eager-fetching clog the fetch queue, delaying the download of any scripts included via document.write().    Vendors have &#039;&#039;&#039;chosen&#039;&#039;&#039; to assume this risk though, since its probability is low and the benefit high.  &lt;br /&gt;
&lt;br /&gt;
Likewise, vendors can calculate the risk/reward for script-inserted scripts and will likely make the same decision -- they implement this exact behavior for images.  Script loaders should respect the fact that a vendor has consciously chosen &#039;&#039;&#039;not&#039;&#039;&#039; to support parallelism for script-inserted scripts.  Providing a means by which this decision can be circumvented undermines their choice.   I believe it was in that spirit the specification leaves eager fetching script resources as a suggestion.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 21:39, 23 December 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5673</id>
		<title>Talk:Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5673"/>
		<updated>2010-12-23T21:14:14Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* Encourage Vendors to Adopt the Current Performance Suggestion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please discuss the proposal here. All informal feedback is welcomed, and when it&#039;s appropriate, please add content to the main page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What about CommonJS / RequireJS? ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m not sure we need to complicate the HTML or browser engines in order to satisfy the advanced use cases.  To me it seems that the JavaScript langauge itself could abstract the requirements and let the browser vendors implement whatever solution they see fit.  Specifically, if JavaScript provided the define() and require() calls proposed in the CommonJS &amp;quot;specifications&amp;quot; (and implemented by [http://requirejs.org/docs/api.html RequireJS], [http://svn.dojotoolkit.org/src/dojo/trunk/_base/_loader/loader.js dojo (trunk)], and others *Yabble?), then browsers could just load and evaluate scripts as fast as possible without regard to script execution order.  &lt;br /&gt;
&lt;br /&gt;
This would solve all of the problems except for the current inability to use loaders like LABjs in FF4 or webkit.  To solve that problem, we should consider keeping the existing functionality or triggering the deprecated functionality when needed.&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
=== Response ===&lt;br /&gt;
&lt;br /&gt;
This is a valid point except that it assumes that all code that needs to be loaded is &amp;quot;modular&amp;quot;... in fact, most code on the internet that needs to be loaded is NOT modular, and instead requires particular ordering when being loaded... for instance, &amp;quot;jquery&amp;quot; and &amp;quot;jquery-ui&amp;quot; -- jQuery must be run before jQuery-UI is loaded and run.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The spirit of this proposal is to add the facility to native browser (rendering engine, specifically) behavior, such that any and all existing content is able to be loaded (even with dependencies and order) without modification.&lt;br /&gt;
&amp;lt;blockquote style=background-color:#eee&amp;gt;&lt;br /&gt;
Are we trying to codify how one would implement this HTML dynamically so I can achieve parallel loading but retain dependency that is inferred in the order? &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: white&amp;quot;&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery-ui.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If so, we must consider the case in which the dependency itself loads additional code which the discussions around `async=false` or even text/cache do not account for.  &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:23, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dependent code should be modular ===&lt;br /&gt;
&lt;br /&gt;
I completely agree, 99% of JavaScript in use today is NOT modular, but that&#039;s arguably because there was no built-in support to make it modular (IMHO, YMMV, RTFM, BBQ, ROFL).  But that doesn&#039;t mean there aren&#039;t dependencies that span script files / script nodes.  I don&#039;t know how many sites would be broken (or if there is any way to determine how many sites would be broken) if/when the latest browsers started loading and evaluating script-injected scripts out of order.  It&#039;s not just LABjs-based sites.  I&#039;ll bet many dojo and YUI sites will break, too (although I don&#039;t know this for a fact because I don&#039;t know exactly how their dynamic script loaders work).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;In any case, breaking existing sites is a BAD IDEA. :)  There should be some way to allow LABjs and other dynamic script loaders to continue to work.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The part I don&#039;t agree with in the proposals is that it should be the job of HTML and/or the browser engine to manage dependencies.  Specifically, I am talking about the scriptGroup element and the &amp;quot;waitFor&amp;quot; attribute.  The &amp;quot;async&amp;quot; attribute may be the right level: it appropriates only general heuristics to the browser: &#039;&#039;load these scripts whenever you like, but load these other scripts in this order&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Detailed dependency management belongs in the modules, though.  This is how it&#039;s done in most environments / languages: import statements, include statements, etc.  It&#039;s no different in JavaScript, if a developer wants to take advantage of some code in another module, she/he should import it into their current module.  This should be the model moving forward.  It&#039;s not hard, it&#039;s not un-web-like, and it&#039;s already being done.  &lt;br /&gt;
&lt;br /&gt;
Existing code can be made to work modularly, too:&lt;br /&gt;
&lt;br /&gt;
1. Identify modules and wrap them with a define() method.&lt;br /&gt;
2. Identify dependencies using either the [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition Asynchronous Module Definition] format or the CommonJS synchronous format&lt;br /&gt;
&lt;br /&gt;
async format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define([&#039;dependency1&#039;, &#039;dependency2&#039;], function (dependency1, dependency2) {&lt;br /&gt;
	/* this is the factory function, return the module inside here */&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sync format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define(function (require, exports, module) {&lt;br /&gt;
	/* this is the factory function, require dependencies and return the module inside here */&lt;br /&gt;
	var dependency1 = require(&#039;dependency1&#039;);&lt;br /&gt;
	var dependency2 = require(&#039;dependency2&#039;);&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the async case, the browser may employ whatever method it sees fit (e.g. parallel) to download the dependencies since the code inside the factory function won&#039;t execute until all of the dependencies are loaded and evaluated.  In the sync case, the browser has no choice but to download and evaluate the dependency before continuing code execution.  It&#039;s conceivable that the browser could find and asynchronously pre-fetch the inline require()&#039;ed dependencies in the sync case.  (RequireJS doesn&#039;t quite do this.  Instead I believe it finds the inline require() calls and converts the module to an async module.)  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;So, in short: don&#039;t break LABjs (or any other script loaders), but don&#039;t extend the spec to manage dependency management from HTML.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Response #2 ==&lt;br /&gt;
&lt;br /&gt;
The cat&#039;s already out of the bag... we&#039;ve got a dozen+ years worth, hundreds of millions of javascript files out there, which are NOT modular, and will not be modified to be modular. &lt;br /&gt;
&lt;br /&gt;
If we&#039;re talking about either trying to change all the JS on the web to be modular, or trying to extend the HTML markup spec to include a better facility for accomodating the existing script content, I think the former is idealistic and &amp;quot;correct&amp;quot; but the latter is realistic and &amp;quot;right&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
A modular loading system will only work for modular code, but a general loading mechanism in HTML (like the &amp;amp;lt;script&amp;gt; tag) can load both modular and non-modular code, which is why that more general mechanism is what&#039;s in HTML right now and not some more specialized loading API that only loads a small percentage of JavaScript code out there.&lt;br /&gt;
&lt;br /&gt;
The &amp;amp;lt;script&amp;gt; tag has worked fine forever, and there&#039;s been no real big push to do away with it in favor of having all loading handled by JavaScript -- in fact, that would be impossible because if you had no way to load JS onto the page with a &amp;amp;lt;script&amp;gt; tag, then no JavaScript could run on a page to load more code. So I don&#039;t agree that we should stop adding functionality to the HTML loading mechanism and only focus on JavaScript.&lt;br /&gt;
&lt;br /&gt;
If we agree that the &amp;amp;lt;script&amp;gt; tag itself is not only required but normative, then I&#039;m not sure why decorating the &amp;amp;lt;script&amp;gt; tag with additional behavior to help it be more powerful is a bad pattern. We&#039;ve addded &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; already. I&#039;m not sure I understand why adding a wrapper tag called &amp;quot;scriptGroup&amp;quot; would be that much different than attributes on the &amp;amp;lt;script&amp;gt; tag?&lt;br /&gt;
&lt;br /&gt;
I also don&#039;t think that &amp;quot;scriptGroup&amp;quot; constitutes &amp;quot;dependency management&amp;quot;. &amp;quot;scriptGroup&amp;quot; is a semantic way for a web author to express that they want to group a set of scripts together ONLY so far as execution order behavior is concerned. It implies nothing more to it (that &amp;quot;dependency management&amp;quot; would imply) than that.&lt;br /&gt;
&lt;br /&gt;
For instance, consider this: if JavaScript had been built with non-global context and statement level context and sandboxing and such things, we&#039;d have a much more secure JavaScript right now. But just because JavaScript may someday be taught some new tricks in terms of security, that doesn&#039;t mean that &amp;quot;now&amp;quot; HTML shouldn&#039;t try to help solve the problem. If for instance the &amp;amp;lt;frag&amp;gt; tag can be used to create a sandboxed environment for third-party JavaScript code to run in, this is a much easier way to address the security problem than to suggest we have to wait for ES-Harmony to add extra syntax to the language to accomplish the same thing.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 02:13, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Text/cache solution ==&lt;br /&gt;
&lt;br /&gt;
It seems to me that having a real text/cache script type, or a similar element that fires a load/error event and provides a .text property gets you where you need to be. You could setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/JavaScript&amp;quot;) or use the text to create a new script element. Or a new style element, or whatever. That puts you in control of when script or CSS is interpreted. With async as the default, you don&#039;t need a new ordered attribute as that&#039;s easily managed in script.&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;text/cache&amp;quot; response ==&lt;br /&gt;
&lt;br /&gt;
On the surface, this idea sounds like it&#039;s pretty similar to &amp;amp;lt;link rel=prefetch&amp;gt; -- in other words, we&#039;ve already standardized a way to prefetch a resource into cache, and probably in a better way than the hack that I did in LABjs of just relying on it fetching unrecognizable content.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it still suffers some similar problems to &amp;amp;lt;link rel=prefetch&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Firstly, if the notion is that you&#039;d use &amp;amp;lt;script type=&amp;quot;text/cache&amp;quot;&amp;gt; to prefetch, and then you&#039;d make a second request for the resource with a real &amp;amp;lt;script type=&amp;quot;text/javascript&amp;gt; node, it suffers the faulty assumption that the resource was served with proper cache headers.&lt;br /&gt;
&lt;br /&gt;
If we try to avoid the need for the second request by suggesting that you can access the `text` property of the node (and then eval() or inject that code when you want to execute it), this runs afoul of the same-origin policy problem if you requested the script from a non-local domain.&lt;br /&gt;
&lt;br /&gt;
The part of your suggestion that holds water would be if, given a &amp;quot;prefetched&amp;quot; script node that didn&#039;t execute yet, I could simply change that node&#039;s `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;, and that would explicitly trigger the browser to immediately execute it. &lt;br /&gt;
&lt;br /&gt;
This is an interesting idea. I can see though that it perhaps has some potential complications. &lt;br /&gt;
&lt;br /&gt;
For instance, would the browser have to keep a &amp;quot;hasExecuted&amp;quot; internal flag, so that changing the `type` value would only at most result in one execution? Also, if the script node in question is loaded but not executed, can the page alter the script code (by setting its `text` property) before making the change to the `type` value? In that case, should the browser execute the original code or the modified code? I can see security implications and confusion abounding in that behavior.&lt;br /&gt;
&lt;br /&gt;
Lastly, as mentioned above, this basically copies (in a similar but not exactly identical way) the &amp;amp;lt;link rel=prefetch&amp;gt; behavior. It may be seen as a negative to be trying to step on the toes of &amp;amp;lt;link rel=prefetch&amp;gt;, and also it may be more confusing to the general public as to why you&#039;d use one technique or the other, given their differences being so nuanced.&lt;br /&gt;
&lt;br /&gt;
That having been said, I can see that it&#039;s a viable alternate proposal. It&#039;s worth adding a note to that section of the main Wiki page and to getting some feedback from browser vendors on if they feel this is a more realistic/suitable solution to the use-case.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #eee&amp;quot;&amp;gt;&lt;br /&gt;
The difference between pre-fetching and this proposal seems pretty clear: Prefetching, if not performed now, will eventually be done once the user explicitly requests the page. while the &amp;quot;text/cache&amp;quot; solution indicates that the resource should load &#039;&#039;&#039;immediately&#039;&#039;&#039;, not during idle time. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:10, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 20:56, 4 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== RequireJS order support ==&lt;br /&gt;
&lt;br /&gt;
I am the main developer for RequireJS, and just want to voice my support for a solution that works on the script element itself, either by leveraging the async attribute or allowing something like an &amp;quot;order&amp;quot; boolean attribute that would allow specifying a dynamically added script element should be executed in the order that it appears in the DOM. This capability should be something can be capability detected to avoid browser sniffing.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Why shouldn&#039;t dependency management be implemented in high-level code and the browser simply provide a means by which parallel loading can be achieved?  As you know, there is a considerable amount of nuance.  I&#039;m of the opinion that implementing dependency management in the engine will eventually lead us right back to where we were 10 years ago with inline script tags which provides an easy method for dependency management at the expense of unmanaged blocking and an inability to detect or adapt to errors. &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
There are many scripts on the web today that have implicit dependencies that should be loaded in a specific order, but the application developer will want to use dynamically created script elements for best performance. jQuery plugins that depend on the jQuery script already been executed in the page are a good example.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Agreed, but I don&#039;t believe the proposals allow for proper emulation of the dependency management provided by script tags.  Prototype.js, for example, loads its core modules dynamically (using document.write so maybe not the best example...).  When prototype.js is included via script tags, ensuing script blocks are free to &amp;quot;depend&amp;quot; on all of these modules; Dynamically creating a dependency on prototype.js by loading both with the `async=true` property will fail since prototype.js won&#039;t be able to &amp;quot;jump the queue&amp;quot; and add insure its core modules load before its extensions.  &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#ccc&amp;quot;&amp;gt;&lt;br /&gt;
I have to admit, you raise a valid point with respect to that common usage. The YUI model (where the framework is responsible for all loading) is perhaps the more appropriate model to move toward, though. Or, the framework doesn&#039;t auto-load its own dependencies at all. In either case, I think it&#039;s cleaner to have one loading mechanism in play rather than two or more competing ones, because as you point out, this is going to get messy. I still am not sure this means that the async=false proposal is lacking, because as I think about how complicated such a split loading would be with your `readyState` proposal, that seems even worse/more complicated to me. [[User:Getify|Getify]] 20:06, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
I would not argue &#039;&#039;&#039;against&#039;&#039;&#039; a global queue for synchronized execution, I just think the usefulness of such a construct declines as scripts that &amp;quot;I don&#039;t care about&amp;quot; are added.  It&#039;s my opinion the spec should provide the ability for high-level code to implement similar constructs, regardless of how complex it may be to do so. &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
That being said, I don&#039;t think it&#039;s any more complicated than existing models.  Here&#039;s a demonstration of an [http://digital-fulcrum.com/executionorder/ IE-only parallel-loading, synchronously-executing script queue] implemented in 40 lines of code.  It tests both cached and un-cached scripts (from the LABjs test suite) and has been tested and found to be working in IE6-8. &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[User:Serverherder|Serverherder]] 01:52, 16 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
- James Burke&lt;br /&gt;
&lt;br /&gt;
== Vendors Should Implement the Existing Suggestion ==&lt;br /&gt;
&lt;br /&gt;
Since the spec all ready includes a suggestion to download resources when the SRC attribute is set, parallel loading is an option the &#039;&#039;&#039;vendor&#039;&#039;&#039; chooses to implement and not something a script loader should be able to require.  Vendors that don&#039;t implement the suggestion will run the risk of being less performant in these situations.  That, however, is &#039;&#039;&#039;their&#039;&#039;&#039; choice to make as the spec suggests.  If the benefits of parallel loading dependencies are so great, users will opt for this in their choice of agent or vendors can adopt the existing mechanism.&lt;br /&gt;
&lt;br /&gt;
== The Current Suggestion Should be Changed to a Mandate ==&lt;br /&gt;
&lt;br /&gt;
The spec is pretty clear on why it chose to make this optional.  If dependent script loading is so common that browsers that adopt the suggestion enjoy considerably better performance, the user will eventually decide to opt for those implementations.  On the other hand, if it is more common that scripts are created and never inserted, leading to wasted bandwidth and clogged fetching queues, the converse will occur.  Either way, by making it optional, the spec hedges its bet and is more prone to be future-proof as the habits of script developers evolve.&lt;br /&gt;
&lt;br /&gt;
== Modify the specification so parallel-loading is configurable  ==&lt;br /&gt;
The specification expresses the reasons parallel loading should not be done.  To this point, allowing developers a means to &#039;&#039;&#039;require&#039;&#039;&#039; resources be downloaded in parallel is in direct opposition to the spec&#039;s all ready stated position.  To this end, I see no purpose for async=true: A browser that hopes to be highly performant should implement the spec&#039;s suggestion to improve performance.  Developers should not be able to circumvent the vendor&#039;s attempt to be conservative in its use of bandwidth simply to achieve ordered execution.&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5672</id>
		<title>Talk:Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5672"/>
		<updated>2010-12-23T21:09:44Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* Encourage Vendors to Adopt the Current Performance Suggestion */ new section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please discuss the proposal here. All informal feedback is welcomed, and when it&#039;s appropriate, please add content to the main page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What about CommonJS / RequireJS? ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m not sure we need to complicate the HTML or browser engines in order to satisfy the advanced use cases.  To me it seems that the JavaScript langauge itself could abstract the requirements and let the browser vendors implement whatever solution they see fit.  Specifically, if JavaScript provided the define() and require() calls proposed in the CommonJS &amp;quot;specifications&amp;quot; (and implemented by [http://requirejs.org/docs/api.html RequireJS], [http://svn.dojotoolkit.org/src/dojo/trunk/_base/_loader/loader.js dojo (trunk)], and others *Yabble?), then browsers could just load and evaluate scripts as fast as possible without regard to script execution order.  &lt;br /&gt;
&lt;br /&gt;
This would solve all of the problems except for the current inability to use loaders like LABjs in FF4 or webkit.  To solve that problem, we should consider keeping the existing functionality or triggering the deprecated functionality when needed.&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
=== Response ===&lt;br /&gt;
&lt;br /&gt;
This is a valid point except that it assumes that all code that needs to be loaded is &amp;quot;modular&amp;quot;... in fact, most code on the internet that needs to be loaded is NOT modular, and instead requires particular ordering when being loaded... for instance, &amp;quot;jquery&amp;quot; and &amp;quot;jquery-ui&amp;quot; -- jQuery must be run before jQuery-UI is loaded and run.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The spirit of this proposal is to add the facility to native browser (rendering engine, specifically) behavior, such that any and all existing content is able to be loaded (even with dependencies and order) without modification.&lt;br /&gt;
&amp;lt;blockquote style=background-color:#eee&amp;gt;&lt;br /&gt;
Are we trying to codify how one would implement this HTML dynamically so I can achieve parallel loading but retain dependency that is inferred in the order? &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: white&amp;quot;&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery-ui.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If so, we must consider the case in which the dependency itself loads additional code which the discussions around `async=false` or even text/cache do not account for.  &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:23, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dependent code should be modular ===&lt;br /&gt;
&lt;br /&gt;
I completely agree, 99% of JavaScript in use today is NOT modular, but that&#039;s arguably because there was no built-in support to make it modular (IMHO, YMMV, RTFM, BBQ, ROFL).  But that doesn&#039;t mean there aren&#039;t dependencies that span script files / script nodes.  I don&#039;t know how many sites would be broken (or if there is any way to determine how many sites would be broken) if/when the latest browsers started loading and evaluating script-injected scripts out of order.  It&#039;s not just LABjs-based sites.  I&#039;ll bet many dojo and YUI sites will break, too (although I don&#039;t know this for a fact because I don&#039;t know exactly how their dynamic script loaders work).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;In any case, breaking existing sites is a BAD IDEA. :)  There should be some way to allow LABjs and other dynamic script loaders to continue to work.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The part I don&#039;t agree with in the proposals is that it should be the job of HTML and/or the browser engine to manage dependencies.  Specifically, I am talking about the scriptGroup element and the &amp;quot;waitFor&amp;quot; attribute.  The &amp;quot;async&amp;quot; attribute may be the right level: it appropriates only general heuristics to the browser: &#039;&#039;load these scripts whenever you like, but load these other scripts in this order&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Detailed dependency management belongs in the modules, though.  This is how it&#039;s done in most environments / languages: import statements, include statements, etc.  It&#039;s no different in JavaScript, if a developer wants to take advantage of some code in another module, she/he should import it into their current module.  This should be the model moving forward.  It&#039;s not hard, it&#039;s not un-web-like, and it&#039;s already being done.  &lt;br /&gt;
&lt;br /&gt;
Existing code can be made to work modularly, too:&lt;br /&gt;
&lt;br /&gt;
1. Identify modules and wrap them with a define() method.&lt;br /&gt;
2. Identify dependencies using either the [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition Asynchronous Module Definition] format or the CommonJS synchronous format&lt;br /&gt;
&lt;br /&gt;
async format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define([&#039;dependency1&#039;, &#039;dependency2&#039;], function (dependency1, dependency2) {&lt;br /&gt;
	/* this is the factory function, return the module inside here */&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sync format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define(function (require, exports, module) {&lt;br /&gt;
	/* this is the factory function, require dependencies and return the module inside here */&lt;br /&gt;
	var dependency1 = require(&#039;dependency1&#039;);&lt;br /&gt;
	var dependency2 = require(&#039;dependency2&#039;);&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the async case, the browser may employ whatever method it sees fit (e.g. parallel) to download the dependencies since the code inside the factory function won&#039;t execute until all of the dependencies are loaded and evaluated.  In the sync case, the browser has no choice but to download and evaluate the dependency before continuing code execution.  It&#039;s conceivable that the browser could find and asynchronously pre-fetch the inline require()&#039;ed dependencies in the sync case.  (RequireJS doesn&#039;t quite do this.  Instead I believe it finds the inline require() calls and converts the module to an async module.)  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;So, in short: don&#039;t break LABjs (or any other script loaders), but don&#039;t extend the spec to manage dependency management from HTML.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Response #2 ==&lt;br /&gt;
&lt;br /&gt;
The cat&#039;s already out of the bag... we&#039;ve got a dozen+ years worth, hundreds of millions of javascript files out there, which are NOT modular, and will not be modified to be modular. &lt;br /&gt;
&lt;br /&gt;
If we&#039;re talking about either trying to change all the JS on the web to be modular, or trying to extend the HTML markup spec to include a better facility for accomodating the existing script content, I think the former is idealistic and &amp;quot;correct&amp;quot; but the latter is realistic and &amp;quot;right&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
A modular loading system will only work for modular code, but a general loading mechanism in HTML (like the &amp;amp;lt;script&amp;gt; tag) can load both modular and non-modular code, which is why that more general mechanism is what&#039;s in HTML right now and not some more specialized loading API that only loads a small percentage of JavaScript code out there.&lt;br /&gt;
&lt;br /&gt;
The &amp;amp;lt;script&amp;gt; tag has worked fine forever, and there&#039;s been no real big push to do away with it in favor of having all loading handled by JavaScript -- in fact, that would be impossible because if you had no way to load JS onto the page with a &amp;amp;lt;script&amp;gt; tag, then no JavaScript could run on a page to load more code. So I don&#039;t agree that we should stop adding functionality to the HTML loading mechanism and only focus on JavaScript.&lt;br /&gt;
&lt;br /&gt;
If we agree that the &amp;amp;lt;script&amp;gt; tag itself is not only required but normative, then I&#039;m not sure why decorating the &amp;amp;lt;script&amp;gt; tag with additional behavior to help it be more powerful is a bad pattern. We&#039;ve addded &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; already. I&#039;m not sure I understand why adding a wrapper tag called &amp;quot;scriptGroup&amp;quot; would be that much different than attributes on the &amp;amp;lt;script&amp;gt; tag?&lt;br /&gt;
&lt;br /&gt;
I also don&#039;t think that &amp;quot;scriptGroup&amp;quot; constitutes &amp;quot;dependency management&amp;quot;. &amp;quot;scriptGroup&amp;quot; is a semantic way for a web author to express that they want to group a set of scripts together ONLY so far as execution order behavior is concerned. It implies nothing more to it (that &amp;quot;dependency management&amp;quot; would imply) than that.&lt;br /&gt;
&lt;br /&gt;
For instance, consider this: if JavaScript had been built with non-global context and statement level context and sandboxing and such things, we&#039;d have a much more secure JavaScript right now. But just because JavaScript may someday be taught some new tricks in terms of security, that doesn&#039;t mean that &amp;quot;now&amp;quot; HTML shouldn&#039;t try to help solve the problem. If for instance the &amp;amp;lt;frag&amp;gt; tag can be used to create a sandboxed environment for third-party JavaScript code to run in, this is a much easier way to address the security problem than to suggest we have to wait for ES-Harmony to add extra syntax to the language to accomplish the same thing.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 02:13, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Text/cache solution ==&lt;br /&gt;
&lt;br /&gt;
It seems to me that having a real text/cache script type, or a similar element that fires a load/error event and provides a .text property gets you where you need to be. You could setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/JavaScript&amp;quot;) or use the text to create a new script element. Or a new style element, or whatever. That puts you in control of when script or CSS is interpreted. With async as the default, you don&#039;t need a new ordered attribute as that&#039;s easily managed in script.&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;text/cache&amp;quot; response ==&lt;br /&gt;
&lt;br /&gt;
On the surface, this idea sounds like it&#039;s pretty similar to &amp;amp;lt;link rel=prefetch&amp;gt; -- in other words, we&#039;ve already standardized a way to prefetch a resource into cache, and probably in a better way than the hack that I did in LABjs of just relying on it fetching unrecognizable content.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it still suffers some similar problems to &amp;amp;lt;link rel=prefetch&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Firstly, if the notion is that you&#039;d use &amp;amp;lt;script type=&amp;quot;text/cache&amp;quot;&amp;gt; to prefetch, and then you&#039;d make a second request for the resource with a real &amp;amp;lt;script type=&amp;quot;text/javascript&amp;gt; node, it suffers the faulty assumption that the resource was served with proper cache headers.&lt;br /&gt;
&lt;br /&gt;
If we try to avoid the need for the second request by suggesting that you can access the `text` property of the node (and then eval() or inject that code when you want to execute it), this runs afoul of the same-origin policy problem if you requested the script from a non-local domain.&lt;br /&gt;
&lt;br /&gt;
The part of your suggestion that holds water would be if, given a &amp;quot;prefetched&amp;quot; script node that didn&#039;t execute yet, I could simply change that node&#039;s `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;, and that would explicitly trigger the browser to immediately execute it. &lt;br /&gt;
&lt;br /&gt;
This is an interesting idea. I can see though that it perhaps has some potential complications. &lt;br /&gt;
&lt;br /&gt;
For instance, would the browser have to keep a &amp;quot;hasExecuted&amp;quot; internal flag, so that changing the `type` value would only at most result in one execution? Also, if the script node in question is loaded but not executed, can the page alter the script code (by setting its `text` property) before making the change to the `type` value? In that case, should the browser execute the original code or the modified code? I can see security implications and confusion abounding in that behavior.&lt;br /&gt;
&lt;br /&gt;
Lastly, as mentioned above, this basically copies (in a similar but not exactly identical way) the &amp;amp;lt;link rel=prefetch&amp;gt; behavior. It may be seen as a negative to be trying to step on the toes of &amp;amp;lt;link rel=prefetch&amp;gt;, and also it may be more confusing to the general public as to why you&#039;d use one technique or the other, given their differences being so nuanced.&lt;br /&gt;
&lt;br /&gt;
That having been said, I can see that it&#039;s a viable alternate proposal. It&#039;s worth adding a note to that section of the main Wiki page and to getting some feedback from browser vendors on if they feel this is a more realistic/suitable solution to the use-case.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #eee&amp;quot;&amp;gt;&lt;br /&gt;
The difference between pre-fetching and this proposal seems pretty clear: Prefetching, if not performed now, will eventually be done once the user explicitly requests the page. while the &amp;quot;text/cache&amp;quot; solution indicates that the resource should load &#039;&#039;&#039;immediately&#039;&#039;&#039;, not during idle time. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:10, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 20:56, 4 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== RequireJS order support ==&lt;br /&gt;
&lt;br /&gt;
I am the main developer for RequireJS, and just want to voice my support for a solution that works on the script element itself, either by leveraging the async attribute or allowing something like an &amp;quot;order&amp;quot; boolean attribute that would allow specifying a dynamically added script element should be executed in the order that it appears in the DOM. This capability should be something can be capability detected to avoid browser sniffing.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Why shouldn&#039;t dependency management be implemented in high-level code and the browser simply provide a means by which parallel loading can be achieved?  As you know, there is a considerable amount of nuance.  I&#039;m of the opinion that implementing dependency management in the engine will eventually lead us right back to where we were 10 years ago with inline script tags which provides an easy method for dependency management at the expense of unmanaged blocking and an inability to detect or adapt to errors. &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
There are many scripts on the web today that have implicit dependencies that should be loaded in a specific order, but the application developer will want to use dynamically created script elements for best performance. jQuery plugins that depend on the jQuery script already been executed in the page are a good example.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Agreed, but I don&#039;t believe the proposals allow for proper emulation of the dependency management provided by script tags.  Prototype.js, for example, loads its core modules dynamically (using document.write so maybe not the best example...).  When prototype.js is included via script tags, ensuing script blocks are free to &amp;quot;depend&amp;quot; on all of these modules; Dynamically creating a dependency on prototype.js by loading both with the `async=true` property will fail since prototype.js won&#039;t be able to &amp;quot;jump the queue&amp;quot; and add insure its core modules load before its extensions.  &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#ccc&amp;quot;&amp;gt;&lt;br /&gt;
I have to admit, you raise a valid point with respect to that common usage. The YUI model (where the framework is responsible for all loading) is perhaps the more appropriate model to move toward, though. Or, the framework doesn&#039;t auto-load its own dependencies at all. In either case, I think it&#039;s cleaner to have one loading mechanism in play rather than two or more competing ones, because as you point out, this is going to get messy. I still am not sure this means that the async=false proposal is lacking, because as I think about how complicated such a split loading would be with your `readyState` proposal, that seems even worse/more complicated to me. [[User:Getify|Getify]] 20:06, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
I would not argue &#039;&#039;&#039;against&#039;&#039;&#039; a global queue for synchronized execution, I just think the usefulness of such a construct declines as scripts that &amp;quot;I don&#039;t care about&amp;quot; are added.  It&#039;s my opinion the spec should provide the ability for high-level code to implement similar constructs, regardless of how complex it may be to do so. &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
That being said, I don&#039;t think it&#039;s any more complicated than existing models.  Here&#039;s a demonstration of an [http://digital-fulcrum.com/executionorder/ IE-only parallel-loading, synchronously-executing script queue] implemented in 40 lines of code.  It tests both cached and un-cached scripts (from the LABjs test suite) and has been tested and found to be working in IE6-8. &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[User:Serverherder|Serverherder]] 01:52, 16 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
- James Burke&lt;br /&gt;
&lt;br /&gt;
== Vendors Should Implement the Existing Suggestion ==&lt;br /&gt;
&lt;br /&gt;
Since the spec all ready includes a suggestion to download resources when the SRC attribute is set, parallel loading is an option the &#039;&#039;&#039;vendor&#039;&#039;&#039; chooses to implement and not something a script loader should be able to require.  Vendors that don&#039;t implement the suggestion will run the risk of being less performant in these situations.  That, however, is &#039;&#039;&#039;their&#039;&#039;&#039; choice to make as the spec suggests.  If the benefits of parallel loading dependencies are so great, users will opt for this in their choice of agent or vendors can adopt the existing mechanism.&lt;br /&gt;
&lt;br /&gt;
== The Current Suggestion Should be Changed to a Mandate ==&lt;br /&gt;
&lt;br /&gt;
The spec is pretty clear on why it chose to make this optional.  If dependent script loading is so common that browsers that adopt the suggestion enjoy considerably better performance, the user will eventually decide to opt for those implementations.  On the other hand, if it is more common that scripts are created and never inserted, leading to wasted bandwidth and clogged fetching queues, the converse will occur.  Either way, by making it optional, the spec hedges its bet and is more prone to be future-proof as the habits of script developers evolve.&lt;br /&gt;
&lt;br /&gt;
== Encourage Vendors to Adopt the Current Performance Suggestion ==&lt;br /&gt;
&lt;br /&gt;
Yes!&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5671</id>
		<title>Talk:Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5671"/>
		<updated>2010-12-23T21:09:08Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* The Current Suggestion Should be Changed to a Mandate */ new section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please discuss the proposal here. All informal feedback is welcomed, and when it&#039;s appropriate, please add content to the main page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What about CommonJS / RequireJS? ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m not sure we need to complicate the HTML or browser engines in order to satisfy the advanced use cases.  To me it seems that the JavaScript langauge itself could abstract the requirements and let the browser vendors implement whatever solution they see fit.  Specifically, if JavaScript provided the define() and require() calls proposed in the CommonJS &amp;quot;specifications&amp;quot; (and implemented by [http://requirejs.org/docs/api.html RequireJS], [http://svn.dojotoolkit.org/src/dojo/trunk/_base/_loader/loader.js dojo (trunk)], and others *Yabble?), then browsers could just load and evaluate scripts as fast as possible without regard to script execution order.  &lt;br /&gt;
&lt;br /&gt;
This would solve all of the problems except for the current inability to use loaders like LABjs in FF4 or webkit.  To solve that problem, we should consider keeping the existing functionality or triggering the deprecated functionality when needed.&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
=== Response ===&lt;br /&gt;
&lt;br /&gt;
This is a valid point except that it assumes that all code that needs to be loaded is &amp;quot;modular&amp;quot;... in fact, most code on the internet that needs to be loaded is NOT modular, and instead requires particular ordering when being loaded... for instance, &amp;quot;jquery&amp;quot; and &amp;quot;jquery-ui&amp;quot; -- jQuery must be run before jQuery-UI is loaded and run.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The spirit of this proposal is to add the facility to native browser (rendering engine, specifically) behavior, such that any and all existing content is able to be loaded (even with dependencies and order) without modification.&lt;br /&gt;
&amp;lt;blockquote style=background-color:#eee&amp;gt;&lt;br /&gt;
Are we trying to codify how one would implement this HTML dynamically so I can achieve parallel loading but retain dependency that is inferred in the order? &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: white&amp;quot;&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery-ui.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If so, we must consider the case in which the dependency itself loads additional code which the discussions around `async=false` or even text/cache do not account for.  &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:23, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dependent code should be modular ===&lt;br /&gt;
&lt;br /&gt;
I completely agree, 99% of JavaScript in use today is NOT modular, but that&#039;s arguably because there was no built-in support to make it modular (IMHO, YMMV, RTFM, BBQ, ROFL).  But that doesn&#039;t mean there aren&#039;t dependencies that span script files / script nodes.  I don&#039;t know how many sites would be broken (or if there is any way to determine how many sites would be broken) if/when the latest browsers started loading and evaluating script-injected scripts out of order.  It&#039;s not just LABjs-based sites.  I&#039;ll bet many dojo and YUI sites will break, too (although I don&#039;t know this for a fact because I don&#039;t know exactly how their dynamic script loaders work).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;In any case, breaking existing sites is a BAD IDEA. :)  There should be some way to allow LABjs and other dynamic script loaders to continue to work.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The part I don&#039;t agree with in the proposals is that it should be the job of HTML and/or the browser engine to manage dependencies.  Specifically, I am talking about the scriptGroup element and the &amp;quot;waitFor&amp;quot; attribute.  The &amp;quot;async&amp;quot; attribute may be the right level: it appropriates only general heuristics to the browser: &#039;&#039;load these scripts whenever you like, but load these other scripts in this order&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Detailed dependency management belongs in the modules, though.  This is how it&#039;s done in most environments / languages: import statements, include statements, etc.  It&#039;s no different in JavaScript, if a developer wants to take advantage of some code in another module, she/he should import it into their current module.  This should be the model moving forward.  It&#039;s not hard, it&#039;s not un-web-like, and it&#039;s already being done.  &lt;br /&gt;
&lt;br /&gt;
Existing code can be made to work modularly, too:&lt;br /&gt;
&lt;br /&gt;
1. Identify modules and wrap them with a define() method.&lt;br /&gt;
2. Identify dependencies using either the [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition Asynchronous Module Definition] format or the CommonJS synchronous format&lt;br /&gt;
&lt;br /&gt;
async format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define([&#039;dependency1&#039;, &#039;dependency2&#039;], function (dependency1, dependency2) {&lt;br /&gt;
	/* this is the factory function, return the module inside here */&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sync format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define(function (require, exports, module) {&lt;br /&gt;
	/* this is the factory function, require dependencies and return the module inside here */&lt;br /&gt;
	var dependency1 = require(&#039;dependency1&#039;);&lt;br /&gt;
	var dependency2 = require(&#039;dependency2&#039;);&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the async case, the browser may employ whatever method it sees fit (e.g. parallel) to download the dependencies since the code inside the factory function won&#039;t execute until all of the dependencies are loaded and evaluated.  In the sync case, the browser has no choice but to download and evaluate the dependency before continuing code execution.  It&#039;s conceivable that the browser could find and asynchronously pre-fetch the inline require()&#039;ed dependencies in the sync case.  (RequireJS doesn&#039;t quite do this.  Instead I believe it finds the inline require() calls and converts the module to an async module.)  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;So, in short: don&#039;t break LABjs (or any other script loaders), but don&#039;t extend the spec to manage dependency management from HTML.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Response #2 ==&lt;br /&gt;
&lt;br /&gt;
The cat&#039;s already out of the bag... we&#039;ve got a dozen+ years worth, hundreds of millions of javascript files out there, which are NOT modular, and will not be modified to be modular. &lt;br /&gt;
&lt;br /&gt;
If we&#039;re talking about either trying to change all the JS on the web to be modular, or trying to extend the HTML markup spec to include a better facility for accomodating the existing script content, I think the former is idealistic and &amp;quot;correct&amp;quot; but the latter is realistic and &amp;quot;right&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
A modular loading system will only work for modular code, but a general loading mechanism in HTML (like the &amp;amp;lt;script&amp;gt; tag) can load both modular and non-modular code, which is why that more general mechanism is what&#039;s in HTML right now and not some more specialized loading API that only loads a small percentage of JavaScript code out there.&lt;br /&gt;
&lt;br /&gt;
The &amp;amp;lt;script&amp;gt; tag has worked fine forever, and there&#039;s been no real big push to do away with it in favor of having all loading handled by JavaScript -- in fact, that would be impossible because if you had no way to load JS onto the page with a &amp;amp;lt;script&amp;gt; tag, then no JavaScript could run on a page to load more code. So I don&#039;t agree that we should stop adding functionality to the HTML loading mechanism and only focus on JavaScript.&lt;br /&gt;
&lt;br /&gt;
If we agree that the &amp;amp;lt;script&amp;gt; tag itself is not only required but normative, then I&#039;m not sure why decorating the &amp;amp;lt;script&amp;gt; tag with additional behavior to help it be more powerful is a bad pattern. We&#039;ve addded &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; already. I&#039;m not sure I understand why adding a wrapper tag called &amp;quot;scriptGroup&amp;quot; would be that much different than attributes on the &amp;amp;lt;script&amp;gt; tag?&lt;br /&gt;
&lt;br /&gt;
I also don&#039;t think that &amp;quot;scriptGroup&amp;quot; constitutes &amp;quot;dependency management&amp;quot;. &amp;quot;scriptGroup&amp;quot; is a semantic way for a web author to express that they want to group a set of scripts together ONLY so far as execution order behavior is concerned. It implies nothing more to it (that &amp;quot;dependency management&amp;quot; would imply) than that.&lt;br /&gt;
&lt;br /&gt;
For instance, consider this: if JavaScript had been built with non-global context and statement level context and sandboxing and such things, we&#039;d have a much more secure JavaScript right now. But just because JavaScript may someday be taught some new tricks in terms of security, that doesn&#039;t mean that &amp;quot;now&amp;quot; HTML shouldn&#039;t try to help solve the problem. If for instance the &amp;amp;lt;frag&amp;gt; tag can be used to create a sandboxed environment for third-party JavaScript code to run in, this is a much easier way to address the security problem than to suggest we have to wait for ES-Harmony to add extra syntax to the language to accomplish the same thing.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 02:13, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Text/cache solution ==&lt;br /&gt;
&lt;br /&gt;
It seems to me that having a real text/cache script type, or a similar element that fires a load/error event and provides a .text property gets you where you need to be. You could setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/JavaScript&amp;quot;) or use the text to create a new script element. Or a new style element, or whatever. That puts you in control of when script or CSS is interpreted. With async as the default, you don&#039;t need a new ordered attribute as that&#039;s easily managed in script.&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;text/cache&amp;quot; response ==&lt;br /&gt;
&lt;br /&gt;
On the surface, this idea sounds like it&#039;s pretty similar to &amp;amp;lt;link rel=prefetch&amp;gt; -- in other words, we&#039;ve already standardized a way to prefetch a resource into cache, and probably in a better way than the hack that I did in LABjs of just relying on it fetching unrecognizable content.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it still suffers some similar problems to &amp;amp;lt;link rel=prefetch&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Firstly, if the notion is that you&#039;d use &amp;amp;lt;script type=&amp;quot;text/cache&amp;quot;&amp;gt; to prefetch, and then you&#039;d make a second request for the resource with a real &amp;amp;lt;script type=&amp;quot;text/javascript&amp;gt; node, it suffers the faulty assumption that the resource was served with proper cache headers.&lt;br /&gt;
&lt;br /&gt;
If we try to avoid the need for the second request by suggesting that you can access the `text` property of the node (and then eval() or inject that code when you want to execute it), this runs afoul of the same-origin policy problem if you requested the script from a non-local domain.&lt;br /&gt;
&lt;br /&gt;
The part of your suggestion that holds water would be if, given a &amp;quot;prefetched&amp;quot; script node that didn&#039;t execute yet, I could simply change that node&#039;s `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;, and that would explicitly trigger the browser to immediately execute it. &lt;br /&gt;
&lt;br /&gt;
This is an interesting idea. I can see though that it perhaps has some potential complications. &lt;br /&gt;
&lt;br /&gt;
For instance, would the browser have to keep a &amp;quot;hasExecuted&amp;quot; internal flag, so that changing the `type` value would only at most result in one execution? Also, if the script node in question is loaded but not executed, can the page alter the script code (by setting its `text` property) before making the change to the `type` value? In that case, should the browser execute the original code or the modified code? I can see security implications and confusion abounding in that behavior.&lt;br /&gt;
&lt;br /&gt;
Lastly, as mentioned above, this basically copies (in a similar but not exactly identical way) the &amp;amp;lt;link rel=prefetch&amp;gt; behavior. It may be seen as a negative to be trying to step on the toes of &amp;amp;lt;link rel=prefetch&amp;gt;, and also it may be more confusing to the general public as to why you&#039;d use one technique or the other, given their differences being so nuanced.&lt;br /&gt;
&lt;br /&gt;
That having been said, I can see that it&#039;s a viable alternate proposal. It&#039;s worth adding a note to that section of the main Wiki page and to getting some feedback from browser vendors on if they feel this is a more realistic/suitable solution to the use-case.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #eee&amp;quot;&amp;gt;&lt;br /&gt;
The difference between pre-fetching and this proposal seems pretty clear: Prefetching, if not performed now, will eventually be done once the user explicitly requests the page. while the &amp;quot;text/cache&amp;quot; solution indicates that the resource should load &#039;&#039;&#039;immediately&#039;&#039;&#039;, not during idle time. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:10, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 20:56, 4 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== RequireJS order support ==&lt;br /&gt;
&lt;br /&gt;
I am the main developer for RequireJS, and just want to voice my support for a solution that works on the script element itself, either by leveraging the async attribute or allowing something like an &amp;quot;order&amp;quot; boolean attribute that would allow specifying a dynamically added script element should be executed in the order that it appears in the DOM. This capability should be something can be capability detected to avoid browser sniffing.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Why shouldn&#039;t dependency management be implemented in high-level code and the browser simply provide a means by which parallel loading can be achieved?  As you know, there is a considerable amount of nuance.  I&#039;m of the opinion that implementing dependency management in the engine will eventually lead us right back to where we were 10 years ago with inline script tags which provides an easy method for dependency management at the expense of unmanaged blocking and an inability to detect or adapt to errors. &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
There are many scripts on the web today that have implicit dependencies that should be loaded in a specific order, but the application developer will want to use dynamically created script elements for best performance. jQuery plugins that depend on the jQuery script already been executed in the page are a good example.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Agreed, but I don&#039;t believe the proposals allow for proper emulation of the dependency management provided by script tags.  Prototype.js, for example, loads its core modules dynamically (using document.write so maybe not the best example...).  When prototype.js is included via script tags, ensuing script blocks are free to &amp;quot;depend&amp;quot; on all of these modules; Dynamically creating a dependency on prototype.js by loading both with the `async=true` property will fail since prototype.js won&#039;t be able to &amp;quot;jump the queue&amp;quot; and add insure its core modules load before its extensions.  &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#ccc&amp;quot;&amp;gt;&lt;br /&gt;
I have to admit, you raise a valid point with respect to that common usage. The YUI model (where the framework is responsible for all loading) is perhaps the more appropriate model to move toward, though. Or, the framework doesn&#039;t auto-load its own dependencies at all. In either case, I think it&#039;s cleaner to have one loading mechanism in play rather than two or more competing ones, because as you point out, this is going to get messy. I still am not sure this means that the async=false proposal is lacking, because as I think about how complicated such a split loading would be with your `readyState` proposal, that seems even worse/more complicated to me. [[User:Getify|Getify]] 20:06, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
I would not argue &#039;&#039;&#039;against&#039;&#039;&#039; a global queue for synchronized execution, I just think the usefulness of such a construct declines as scripts that &amp;quot;I don&#039;t care about&amp;quot; are added.  It&#039;s my opinion the spec should provide the ability for high-level code to implement similar constructs, regardless of how complex it may be to do so. &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
That being said, I don&#039;t think it&#039;s any more complicated than existing models.  Here&#039;s a demonstration of an [http://digital-fulcrum.com/executionorder/ IE-only parallel-loading, synchronously-executing script queue] implemented in 40 lines of code.  It tests both cached and un-cached scripts (from the LABjs test suite) and has been tested and found to be working in IE6-8. &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[User:Serverherder|Serverherder]] 01:52, 16 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
- James Burke&lt;br /&gt;
&lt;br /&gt;
== Vendors Should Implement the Existing Suggestion ==&lt;br /&gt;
&lt;br /&gt;
Since the spec all ready includes a suggestion to download resources when the SRC attribute is set, parallel loading is an option the &#039;&#039;&#039;vendor&#039;&#039;&#039; chooses to implement and not something a script loader should be able to require.  Vendors that don&#039;t implement the suggestion will run the risk of being less performant in these situations.  That, however, is &#039;&#039;&#039;their&#039;&#039;&#039; choice to make as the spec suggests.  If the benefits of parallel loading dependencies are so great, users will opt for this in their choice of agent or vendors can adopt the existing mechanism.&lt;br /&gt;
&lt;br /&gt;
== The Current Suggestion Should be Changed to a Mandate ==&lt;br /&gt;
&lt;br /&gt;
The spec is pretty clear on why it chose to make this optional.  If dependent script loading is so common that browsers that adopt the suggestion enjoy considerably better performance, the user will eventually decide to opt for those implementations.  On the other hand, if it is more common that scripts are created and never inserted, leading to wasted bandwidth and clogged fetching queues, the converse will occur.  Either way, by making it optional, the spec hedges its bet and is more prone to be future-proof as the habits of script developers evolve.&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5670</id>
		<title>Talk:Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5670"/>
		<updated>2010-12-23T21:03:17Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* Vendors Should Implement the Existing Suggestion */ new section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please discuss the proposal here. All informal feedback is welcomed, and when it&#039;s appropriate, please add content to the main page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What about CommonJS / RequireJS? ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m not sure we need to complicate the HTML or browser engines in order to satisfy the advanced use cases.  To me it seems that the JavaScript langauge itself could abstract the requirements and let the browser vendors implement whatever solution they see fit.  Specifically, if JavaScript provided the define() and require() calls proposed in the CommonJS &amp;quot;specifications&amp;quot; (and implemented by [http://requirejs.org/docs/api.html RequireJS], [http://svn.dojotoolkit.org/src/dojo/trunk/_base/_loader/loader.js dojo (trunk)], and others *Yabble?), then browsers could just load and evaluate scripts as fast as possible without regard to script execution order.  &lt;br /&gt;
&lt;br /&gt;
This would solve all of the problems except for the current inability to use loaders like LABjs in FF4 or webkit.  To solve that problem, we should consider keeping the existing functionality or triggering the deprecated functionality when needed.&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
=== Response ===&lt;br /&gt;
&lt;br /&gt;
This is a valid point except that it assumes that all code that needs to be loaded is &amp;quot;modular&amp;quot;... in fact, most code on the internet that needs to be loaded is NOT modular, and instead requires particular ordering when being loaded... for instance, &amp;quot;jquery&amp;quot; and &amp;quot;jquery-ui&amp;quot; -- jQuery must be run before jQuery-UI is loaded and run.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The spirit of this proposal is to add the facility to native browser (rendering engine, specifically) behavior, such that any and all existing content is able to be loaded (even with dependencies and order) without modification.&lt;br /&gt;
&amp;lt;blockquote style=background-color:#eee&amp;gt;&lt;br /&gt;
Are we trying to codify how one would implement this HTML dynamically so I can achieve parallel loading but retain dependency that is inferred in the order? &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: white&amp;quot;&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery-ui.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If so, we must consider the case in which the dependency itself loads additional code which the discussions around `async=false` or even text/cache do not account for.  &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:23, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dependent code should be modular ===&lt;br /&gt;
&lt;br /&gt;
I completely agree, 99% of JavaScript in use today is NOT modular, but that&#039;s arguably because there was no built-in support to make it modular (IMHO, YMMV, RTFM, BBQ, ROFL).  But that doesn&#039;t mean there aren&#039;t dependencies that span script files / script nodes.  I don&#039;t know how many sites would be broken (or if there is any way to determine how many sites would be broken) if/when the latest browsers started loading and evaluating script-injected scripts out of order.  It&#039;s not just LABjs-based sites.  I&#039;ll bet many dojo and YUI sites will break, too (although I don&#039;t know this for a fact because I don&#039;t know exactly how their dynamic script loaders work).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;In any case, breaking existing sites is a BAD IDEA. :)  There should be some way to allow LABjs and other dynamic script loaders to continue to work.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The part I don&#039;t agree with in the proposals is that it should be the job of HTML and/or the browser engine to manage dependencies.  Specifically, I am talking about the scriptGroup element and the &amp;quot;waitFor&amp;quot; attribute.  The &amp;quot;async&amp;quot; attribute may be the right level: it appropriates only general heuristics to the browser: &#039;&#039;load these scripts whenever you like, but load these other scripts in this order&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Detailed dependency management belongs in the modules, though.  This is how it&#039;s done in most environments / languages: import statements, include statements, etc.  It&#039;s no different in JavaScript, if a developer wants to take advantage of some code in another module, she/he should import it into their current module.  This should be the model moving forward.  It&#039;s not hard, it&#039;s not un-web-like, and it&#039;s already being done.  &lt;br /&gt;
&lt;br /&gt;
Existing code can be made to work modularly, too:&lt;br /&gt;
&lt;br /&gt;
1. Identify modules and wrap them with a define() method.&lt;br /&gt;
2. Identify dependencies using either the [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition Asynchronous Module Definition] format or the CommonJS synchronous format&lt;br /&gt;
&lt;br /&gt;
async format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define([&#039;dependency1&#039;, &#039;dependency2&#039;], function (dependency1, dependency2) {&lt;br /&gt;
	/* this is the factory function, return the module inside here */&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sync format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define(function (require, exports, module) {&lt;br /&gt;
	/* this is the factory function, require dependencies and return the module inside here */&lt;br /&gt;
	var dependency1 = require(&#039;dependency1&#039;);&lt;br /&gt;
	var dependency2 = require(&#039;dependency2&#039;);&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the async case, the browser may employ whatever method it sees fit (e.g. parallel) to download the dependencies since the code inside the factory function won&#039;t execute until all of the dependencies are loaded and evaluated.  In the sync case, the browser has no choice but to download and evaluate the dependency before continuing code execution.  It&#039;s conceivable that the browser could find and asynchronously pre-fetch the inline require()&#039;ed dependencies in the sync case.  (RequireJS doesn&#039;t quite do this.  Instead I believe it finds the inline require() calls and converts the module to an async module.)  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;So, in short: don&#039;t break LABjs (or any other script loaders), but don&#039;t extend the spec to manage dependency management from HTML.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Response #2 ==&lt;br /&gt;
&lt;br /&gt;
The cat&#039;s already out of the bag... we&#039;ve got a dozen+ years worth, hundreds of millions of javascript files out there, which are NOT modular, and will not be modified to be modular. &lt;br /&gt;
&lt;br /&gt;
If we&#039;re talking about either trying to change all the JS on the web to be modular, or trying to extend the HTML markup spec to include a better facility for accomodating the existing script content, I think the former is idealistic and &amp;quot;correct&amp;quot; but the latter is realistic and &amp;quot;right&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
A modular loading system will only work for modular code, but a general loading mechanism in HTML (like the &amp;amp;lt;script&amp;gt; tag) can load both modular and non-modular code, which is why that more general mechanism is what&#039;s in HTML right now and not some more specialized loading API that only loads a small percentage of JavaScript code out there.&lt;br /&gt;
&lt;br /&gt;
The &amp;amp;lt;script&amp;gt; tag has worked fine forever, and there&#039;s been no real big push to do away with it in favor of having all loading handled by JavaScript -- in fact, that would be impossible because if you had no way to load JS onto the page with a &amp;amp;lt;script&amp;gt; tag, then no JavaScript could run on a page to load more code. So I don&#039;t agree that we should stop adding functionality to the HTML loading mechanism and only focus on JavaScript.&lt;br /&gt;
&lt;br /&gt;
If we agree that the &amp;amp;lt;script&amp;gt; tag itself is not only required but normative, then I&#039;m not sure why decorating the &amp;amp;lt;script&amp;gt; tag with additional behavior to help it be more powerful is a bad pattern. We&#039;ve addded &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; already. I&#039;m not sure I understand why adding a wrapper tag called &amp;quot;scriptGroup&amp;quot; would be that much different than attributes on the &amp;amp;lt;script&amp;gt; tag?&lt;br /&gt;
&lt;br /&gt;
I also don&#039;t think that &amp;quot;scriptGroup&amp;quot; constitutes &amp;quot;dependency management&amp;quot;. &amp;quot;scriptGroup&amp;quot; is a semantic way for a web author to express that they want to group a set of scripts together ONLY so far as execution order behavior is concerned. It implies nothing more to it (that &amp;quot;dependency management&amp;quot; would imply) than that.&lt;br /&gt;
&lt;br /&gt;
For instance, consider this: if JavaScript had been built with non-global context and statement level context and sandboxing and such things, we&#039;d have a much more secure JavaScript right now. But just because JavaScript may someday be taught some new tricks in terms of security, that doesn&#039;t mean that &amp;quot;now&amp;quot; HTML shouldn&#039;t try to help solve the problem. If for instance the &amp;amp;lt;frag&amp;gt; tag can be used to create a sandboxed environment for third-party JavaScript code to run in, this is a much easier way to address the security problem than to suggest we have to wait for ES-Harmony to add extra syntax to the language to accomplish the same thing.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 02:13, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Text/cache solution ==&lt;br /&gt;
&lt;br /&gt;
It seems to me that having a real text/cache script type, or a similar element that fires a load/error event and provides a .text property gets you where you need to be. You could setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/JavaScript&amp;quot;) or use the text to create a new script element. Or a new style element, or whatever. That puts you in control of when script or CSS is interpreted. With async as the default, you don&#039;t need a new ordered attribute as that&#039;s easily managed in script.&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;text/cache&amp;quot; response ==&lt;br /&gt;
&lt;br /&gt;
On the surface, this idea sounds like it&#039;s pretty similar to &amp;amp;lt;link rel=prefetch&amp;gt; -- in other words, we&#039;ve already standardized a way to prefetch a resource into cache, and probably in a better way than the hack that I did in LABjs of just relying on it fetching unrecognizable content.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it still suffers some similar problems to &amp;amp;lt;link rel=prefetch&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Firstly, if the notion is that you&#039;d use &amp;amp;lt;script type=&amp;quot;text/cache&amp;quot;&amp;gt; to prefetch, and then you&#039;d make a second request for the resource with a real &amp;amp;lt;script type=&amp;quot;text/javascript&amp;gt; node, it suffers the faulty assumption that the resource was served with proper cache headers.&lt;br /&gt;
&lt;br /&gt;
If we try to avoid the need for the second request by suggesting that you can access the `text` property of the node (and then eval() or inject that code when you want to execute it), this runs afoul of the same-origin policy problem if you requested the script from a non-local domain.&lt;br /&gt;
&lt;br /&gt;
The part of your suggestion that holds water would be if, given a &amp;quot;prefetched&amp;quot; script node that didn&#039;t execute yet, I could simply change that node&#039;s `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;, and that would explicitly trigger the browser to immediately execute it. &lt;br /&gt;
&lt;br /&gt;
This is an interesting idea. I can see though that it perhaps has some potential complications. &lt;br /&gt;
&lt;br /&gt;
For instance, would the browser have to keep a &amp;quot;hasExecuted&amp;quot; internal flag, so that changing the `type` value would only at most result in one execution? Also, if the script node in question is loaded but not executed, can the page alter the script code (by setting its `text` property) before making the change to the `type` value? In that case, should the browser execute the original code or the modified code? I can see security implications and confusion abounding in that behavior.&lt;br /&gt;
&lt;br /&gt;
Lastly, as mentioned above, this basically copies (in a similar but not exactly identical way) the &amp;amp;lt;link rel=prefetch&amp;gt; behavior. It may be seen as a negative to be trying to step on the toes of &amp;amp;lt;link rel=prefetch&amp;gt;, and also it may be more confusing to the general public as to why you&#039;d use one technique or the other, given their differences being so nuanced.&lt;br /&gt;
&lt;br /&gt;
That having been said, I can see that it&#039;s a viable alternate proposal. It&#039;s worth adding a note to that section of the main Wiki page and to getting some feedback from browser vendors on if they feel this is a more realistic/suitable solution to the use-case.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #eee&amp;quot;&amp;gt;&lt;br /&gt;
The difference between pre-fetching and this proposal seems pretty clear: Prefetching, if not performed now, will eventually be done once the user explicitly requests the page. while the &amp;quot;text/cache&amp;quot; solution indicates that the resource should load &#039;&#039;&#039;immediately&#039;&#039;&#039;, not during idle time. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:10, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 20:56, 4 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== RequireJS order support ==&lt;br /&gt;
&lt;br /&gt;
I am the main developer for RequireJS, and just want to voice my support for a solution that works on the script element itself, either by leveraging the async attribute or allowing something like an &amp;quot;order&amp;quot; boolean attribute that would allow specifying a dynamically added script element should be executed in the order that it appears in the DOM. This capability should be something can be capability detected to avoid browser sniffing.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Why shouldn&#039;t dependency management be implemented in high-level code and the browser simply provide a means by which parallel loading can be achieved?  As you know, there is a considerable amount of nuance.  I&#039;m of the opinion that implementing dependency management in the engine will eventually lead us right back to where we were 10 years ago with inline script tags which provides an easy method for dependency management at the expense of unmanaged blocking and an inability to detect or adapt to errors. &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
There are many scripts on the web today that have implicit dependencies that should be loaded in a specific order, but the application developer will want to use dynamically created script elements for best performance. jQuery plugins that depend on the jQuery script already been executed in the page are a good example.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Agreed, but I don&#039;t believe the proposals allow for proper emulation of the dependency management provided by script tags.  Prototype.js, for example, loads its core modules dynamically (using document.write so maybe not the best example...).  When prototype.js is included via script tags, ensuing script blocks are free to &amp;quot;depend&amp;quot; on all of these modules; Dynamically creating a dependency on prototype.js by loading both with the `async=true` property will fail since prototype.js won&#039;t be able to &amp;quot;jump the queue&amp;quot; and add insure its core modules load before its extensions.  &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#ccc&amp;quot;&amp;gt;&lt;br /&gt;
I have to admit, you raise a valid point with respect to that common usage. The YUI model (where the framework is responsible for all loading) is perhaps the more appropriate model to move toward, though. Or, the framework doesn&#039;t auto-load its own dependencies at all. In either case, I think it&#039;s cleaner to have one loading mechanism in play rather than two or more competing ones, because as you point out, this is going to get messy. I still am not sure this means that the async=false proposal is lacking, because as I think about how complicated such a split loading would be with your `readyState` proposal, that seems even worse/more complicated to me. [[User:Getify|Getify]] 20:06, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
I would not argue &#039;&#039;&#039;against&#039;&#039;&#039; a global queue for synchronized execution, I just think the usefulness of such a construct declines as scripts that &amp;quot;I don&#039;t care about&amp;quot; are added.  It&#039;s my opinion the spec should provide the ability for high-level code to implement similar constructs, regardless of how complex it may be to do so. &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
That being said, I don&#039;t think it&#039;s any more complicated than existing models.  Here&#039;s a demonstration of an [http://digital-fulcrum.com/executionorder/ IE-only parallel-loading, synchronously-executing script queue] implemented in 40 lines of code.  It tests both cached and un-cached scripts (from the LABjs test suite) and has been tested and found to be working in IE6-8. &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[User:Serverherder|Serverherder]] 01:52, 16 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
- James Burke&lt;br /&gt;
&lt;br /&gt;
== Vendors Should Implement the Existing Suggestion ==&lt;br /&gt;
&lt;br /&gt;
Since the spec all ready includes a suggestion to download resources when the SRC attribute is set, parallel loading is an option the &#039;&#039;&#039;vendor&#039;&#039;&#039; chooses to implement and not something a script loader should be able to require.  Vendors that don&#039;t implement the suggestion will run the risk of being less performant in these situations.  That, however, is &#039;&#039;&#039;their&#039;&#039;&#039; choice to make as the spec suggests.  If the benefits of parallel loading dependencies are so great, users will opt for this in their choice of agent or vendors can adopt the existing mechanism.&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Dynamic_Script_Execution_Order&amp;diff=5669</id>
		<title>Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Dynamic_Script_Execution_Order&amp;diff=5669"/>
		<updated>2010-12-23T20:58:48Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* Alternate Proposals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is intended to formalize the discussion around an important but currently underserved use-case (in both spec and various browser implementations): the need for a dynamic script loading facility that can download resources in parallel but ensure that they execute serially in insertion order, for dependency reasons.&lt;br /&gt;
&lt;br /&gt;
A long email thread on the W3C public-html list, which began [http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html here] and for which a recent message is [http://lists.w3.org/Archives/Public/public-html/2010Oct/0415.html here], has been discussing this problem, but the email thread is becoming unruly and hard to track, so this wiki page will now be the official location to discuss the topic.&lt;br /&gt;
&lt;br /&gt;
Briefly, this issue has arisen because recent &amp;quot;nightlies&amp;quot; changes in both Mozilla Gecko and Webkit have broken the ability for script-loaders like [http://labjs.com LABjs] to be able to download scripts in parallel but ensure their execution order. As a result of the discussion, it&#039;s become apparent that both the spec for, and various current browser implementations around, dynamic script loading is incomplete in addressing this use case, and that some change needs to occur.&lt;br /&gt;
&lt;br /&gt;
There is one main proposal that has surfaced from the discussions, with several other alternatives having been discussed. This page will try to distill the long email thread down and clearly present the main proposal, objections, and alternative suggestions.&lt;br /&gt;
&lt;br /&gt;
Please feel free to join the discussion of this topic in the [[Talk:Dynamic_Script_Execution_Order]] area.&lt;br /&gt;
&lt;br /&gt;
== Use Case Description ==&lt;br /&gt;
Script tags/elements can either: &lt;br /&gt;
&lt;br /&gt;
a) appear in the HTML markup (&amp;quot;parser-inserted&amp;quot;), OR&lt;br /&gt;
&lt;br /&gt;
b) be dynamically appended to the DOM using document.createElement() (&amp;quot;script-inserted&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Parser-inserted script tags, up until recent browser versions, had the undesirable performance behavior of loading and executing serially, blocking everything else while doing so. Recently, many browsers have improved the situation by loading the scripts in parallel, but still executing them in order.&lt;br /&gt;
&lt;br /&gt;
On-demand (or dynamic) script loading has emerged in recent years for a variety of different reasons, most notably the performance improvements to address such concerns. It is desired by many different scenarios to be able to download scripts to a page completely independently of the loading of the rest of a page&#039;s resources, or even well after a page has finished loading (&amp;quot;on-demand&amp;quot;).  &lt;br /&gt;
&lt;br /&gt;
Recent additions to HTML spec such as &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; were intended to address the use-case for parser-inserted script elements, but their behaviors have been unhelpful for the on-demand loading use-case (script-inserted script elements).&lt;br /&gt;
&lt;br /&gt;
Thus, script loaders (like [http://labjs.com LABjs]) were developed to give page authors an easy way to specify one or more scripts to load (regardless of when in the life-time of the page that loading is requested), and for as many of them as possible to load in parallel, and for those scripts to be loadable from any local or remote domain location, and for the script loader to be able to control the execution order (if the usage of the script loader&#039;s API expresses the need to) to preserve dependencies between the scripts.&lt;br /&gt;
&lt;br /&gt;
Sometimes, dynamic script loading is used to load totally independent scripts, and thus &amp;quot;as fast as possible&amp;quot; execution is desired. Other times (and possibly more frequently), multiple scripts are loaded with some  dependencies among them, requiring them to execute in a certain order. &lt;br /&gt;
&lt;br /&gt;
What is needed is some facility by which a script loader can express that dynamic script loading either does or does not need execution order preserved among the queue of requested script loadings.&lt;br /&gt;
&lt;br /&gt;
=== Current Limitations ===&lt;br /&gt;
Unfortunately, browser behavior around script-inserted script elements and their loading and execution behavior is splintered. There are, at present, two main camps of behavior:&lt;br /&gt;
&lt;br /&gt;
a) in IE and Webkit (including Chrome), the default behavior for script-inserted script elements is for them all to execute in &amp;quot;as fast as possible&amp;quot; mode, meaning there&#039;s no guarantee about ordering. This effectively makes on-demand (dynamic) script loading impossible to work in parallel-mode if the resources in question have dependencies -- the only straight-forward way to handle things is to load each file and execute, serially, losing the parallel loading performance benefits.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
I&#039;m not sure if this is the case.  &lt;br /&gt;
&lt;br /&gt;
IE will start fetching resources without execution simply by setting the src attribute.  Scripts will not execute, however, until they are added to the document.  Since IE supports the readyState attribute and readystatechange event, it&#039;s possible to load scripts in parallel and execute them in order without resorting to invalid type attribute hack-ery.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:white&amp;quot; lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
script= document.createElement(&amp;quot;SCRIPT&amp;quot;); &lt;br /&gt;
script.onreadystatechange= function(){ &lt;br /&gt;
    if(this.readyState == &#039;loaded&#039;)&lt;br /&gt;
          /* &lt;br /&gt;
             Network fetch is now complete, following&lt;br /&gt;
             triggers synchronous execution.  &lt;br /&gt;
          */&lt;br /&gt;
          document.body.appendChild(this); &lt;br /&gt;
    else if(this.readyState == &amp;quot;complete&amp;quot;)&lt;br /&gt;
          this.onreadystatechange= null; &lt;br /&gt;
}&lt;br /&gt;
script.src= &amp;quot;foo.js&amp;quot;; &lt;br /&gt;
/* Network fetching begins now */&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #ccc&amp;quot;&amp;gt;&lt;br /&gt;
I&#039;ve experimented with such things heavily in the past, and I&#039;m fairly suspicious that this is not reliable across various versions of IE (6-9), nor does it work reliably the same depending on if an element is already in the browser cache or not. I&#039;m not 100% certain that what you suggest is flawed, but I have a strong hunch that it can be shown to have some holes in it for IE loading. I will try to create some test cases to prove or disprove.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
When loading a script that is in the cache, IE requires the event handler be installed prior to setting the `src` attribute.  Otherwise the element&#039;s transition to the &amp;quot;loaded&amp;quot; state will be missed.  IE routinely &amp;quot;skips&amp;quot; ready state transitions when cached scripts are immediately inserted into the DOM so suspicion is understandable; however, delayed insertion works around this &amp;quot;problem&amp;quot;.  The script above has been tested in IE6-8 with scripts in a variety of caching states and found to work correctly. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Moreover, you&#039;re suggesting something that is AFAIK only IE right now, &amp;lt;del&amp;gt;and definitely appears to not be standardized. In the same way that I&#039;m hesitant to continue pinning loading behavior on hacks like the invalid type attribute value, I wouldn&#039;t want to approach loading with this technique (even if it were proven reliable on all IE&#039;s under all caching circumstances) unless it was a serious proposal to the W3C to have this technique be the new standard (as opposed to the current proposal, as implemented by Mozilla and Webkit now).&amp;lt;/del&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Update: the behavior *is* in fact in the spec as a suggestion (aka, with &amp;quot;may&amp;quot; instead of &amp;quot;should&amp;quot;). The wording in question is located in [http://www.w3.org/TR/html5/scripting-1.html#running-a-script HTML5 4.3.1, &amp;quot;Running A Script&amp;quot; algorithm] step, 12, which states:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#f1dac9&amp;quot;&amp;gt;&lt;br /&gt;
For performance reasons, user agents may start fetching the script as soon as the attribute is set, instead, in the hope that the element will be inserted into the document. Either way, once the element is inserted into the document, the load must have started. If the UA performs such prefetching, but the element is never inserted in the document, or the src attribute is dynamically changed, then the user agent will not execute the script, and the fetching process will have been effectively wasted.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 19:32, 23 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
I think you&#039;re right: Only IE impelements this event and property on script elements.  The readystatechange event, however, is widely understood due to the XmlHttpRequest implementation and `readyState` property has been added to the `document` in WebKit, Mozilla and IE. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
That having been said, I think this is at least a viable candidate for &amp;quot;Alternate Proposals&amp;quot; and deserves to be [[Dynamic_Script_Execution_Order#readyState_.22preloading.22|listed as such]]. As always, I welcome input from the community on all the ideas presented here, including this one. But, since the main proposal (async=false) is already being implemented by at least two major browsers, I&#039;m not sure if the tide will be changed or not.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#ddd;&amp;quot;&amp;gt;&lt;br /&gt;
Also, the suggestion of handling the &amp;quot;preload&amp;quot; and deferred execution via the script tag&#039;s `readyState` property is very similar in spirit to the suggestion that was made to explicitly support [[Dynamic_Script_Execution_Order#Explicit_support_for_.22text.2Fcache.22_MIME_type_behavior|preloading into cache without execution]]. As I said, either of those two approaches might work, but they both put more of the onus of complexity in managing multiple dependencies on the high-level code (author, script loader, etc). I&#039;m more in favor of this functionality being explicitly built-in natively into the queues. As always, I welcome comments to any side of this discussion.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 18:35, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
b) in Gecko and Opera, the default behavior for script-inserted script elements is for them all to load in parallel, but execute serially in insertion order. Technically, this makes it impossible to dynamically load independent script elements and have them execute in &amp;quot;as fast as possible&amp;quot; mode.&lt;br /&gt;
&lt;br /&gt;
As described above, both behaviors are desirable under different circumstances, but each of the two camps provides only one behavior, and no way to straightforwardly achieve the other. This obviously creates a big nightmare interoperability-wise when trying to provide a general script loader cross-browser.&lt;br /&gt;
&lt;br /&gt;
Since it is observed that the behavior in (a) is more detrimental (race-condition wise) for the case where dependencies exist, script loaders like LABjs had to find some way around this problem while still attempting the best possible parallel loading performance. However, the trick used is hacky and not completely reliable -- yet it is the best way to solve the use-case in &amp;lt;s&amp;gt;IE and &amp;lt;/s&amp;gt;Webkit. &lt;br /&gt;
&lt;br /&gt;
For Gecko/Opera, the concession was just (silently) made that the lesser-common use case of &amp;quot;as fast as possible&amp;quot; wasn&#039;t possible, but degraded fine to &amp;quot;insertion order execution&amp;quot;, while keeping the parallel loading benefits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
Gecko&#039;s strict execution order creates dependencies between scripts which are unrelated and prevents the ability mitigate the impact of server outages / network latency.  This is exacerbated by the fact that Gecko, unlike IE and WebKit, provides no mechanism to &amp;lt;b&amp;gt;remove&amp;lt;/b&amp;gt; scripts from the execution queue. &lt;br /&gt;
&lt;br /&gt;
Consider the case where JSONP is used to provide auto-completion.  The user types &amp;quot;hello&amp;quot; and the JSONP request is made; however, the &amp;quot;currently&amp;quot; loading script is out-of-date as soon as the user modifies his search to &amp;quot;hello world&amp;quot;.  Gecko&#039;s algorithm requires the out-of-date request load and execute before the second request.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Recently, Gecko landed a [http://hg.mozilla.org/mozilla-central/rev/a60414d076b5 patch] to the trunk that stopped Gecko&#039;s existing behavior of preserving execution order, making script-inserted script elements now execute in &amp;quot;as fast as possible&amp;quot; mode similiar to IE/Webkit. Unfortunately, the &amp;quot;workaround&amp;quot; used in IE/Webkit (described in the next section) for dealing with parallel loading and execution-order dependencies does not work in Gecko, which means presently the use-case in question is now broken in Gecko trunk/FF4 nightlies.&lt;br /&gt;
&lt;br /&gt;
Moreover, Webkit recently landed a [http://trac.webkit.org/changeset/67245 patch] to the trunk that stopped Webkit&#039;s non-standard but long-held behavior (also used in the &amp;quot;workaround&amp;quot; described in the next section) of loading into cache script resources with an unrecognized &amp;quot;type&amp;quot; value, but silently not executing them. This behvaior (while hacky) is central to being able to address the use-case in question in Webkit, so at present, Webkit nightlies are now also entirely broken on the use-case (though in a different way than Gecko).&lt;br /&gt;
&lt;br /&gt;
Both the Gecko change and the Webkit change are well-intentioned, as they are bringing the respective browser more in line with the HTML spec. However, what&#039;s really been demonstrated is that the HTML spec is not properly handling this use-case, and so the goal is not to address the browser issues raised with more awkward hacks, but to address the shortcomings of the spec first, and then encourage all browsers to adhere to such.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
Considering Internet Explorer&#039;s readyState implementation provides a means of both parallel loading and preserving execution order can be achieved, perhaps its &amp;quot;readyState&amp;quot; property and onreadystatechange event should be included. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Current Usage and Workarounds ===&lt;br /&gt;
To work around the limitation in IE/Webkit(prior to the above noted patch) of not being able to rely on script order execution for parallel loaded scripts, a &amp;quot;preloading&amp;quot; trick was developed. This trick relied on non-standard (but long-held) behavior in these browsers that a script-inserted script element with an unrecognized &amp;quot;type&amp;quot; value (such as &amp;quot;script/cache&amp;quot;) would be fetched/loaded, but would not execute. This had the effect of loading the resource into cache, and then firing the &amp;quot;load&amp;quot; handlers to let the page know when the resource was completely in cache. &lt;br /&gt;
&lt;br /&gt;
Assuming that the resource was served with proper caching headers, and was in fact in the cache, it could then be executed (nearly) immediately when it was the proper execution order time by re-requesting the same resource via another script-inserted script element with the proper &amp;quot;text/javascript&amp;quot; type value, pulling the resource from the cache and executing it, without another server round-trip.&lt;br /&gt;
&lt;br /&gt;
Of course, the assumption of proper cache headers is a huge one, and not at all reliable. Some recent estimates by performance optimization specialists have suggested as much as 70% of scripts across the internet are not served with proper caching headers, which means that such scripts would be completely ineffective if loaded using this (or a similar) technique. The script resource would end up being loaded completely a second-time, and the &amp;quot;near immediate&amp;quot; execution would obviously be false, and thus race conditions would ensue.&lt;br /&gt;
&lt;br /&gt;
It&#039;s important to note at this point that the new &amp;amp;lt;link rel=prefetch&amp;gt; facility has been suggested as a better workaround, but it suffers the same ill-fated assumption of script cacheability. Still others have suggested &amp;quot;new Image().src=...&amp;quot; or the [http://www.phpied.com/preload-then-execute/ &amp;amp;lt;object&amp;amp;gt; preloading trick] suggested by Stoyan Stefanov. Again, these tricks unwisely assume cacheability, for the &amp;quot;preloading&amp;quot; trick to solve the use-case in question.&lt;br /&gt;
&lt;br /&gt;
=== At Risk ===&lt;br /&gt;
Currently, there are several large/popular web sites which are either currently (or who intend to soon) use LABjs in such a way as to run afoul of the new Gecko and Webkit behavioral changes with LABjs failing to operate properly. It&#039;s important to note that the problems of race conditions can be subtle and hard to detect, and so merely loading up such sites and failing to observe overt failure is not sufficient.&lt;br /&gt;
&lt;br /&gt;
Sites which are known to have LABjs loading techniques in place with currently broken (or susceptible to such breakage in the near future) behavior are:&lt;br /&gt;
&lt;br /&gt;
* [http://twitter.com Twitter]&lt;br /&gt;
* [http://zappos.com Zappos]&lt;br /&gt;
* [http://vimeo.com Vimeo]&lt;br /&gt;
* [http://mefeedia.com MeFeedia]&lt;br /&gt;
* [http://blog.getify.com Getify Solutions blog (my blog)]&lt;br /&gt;
* [http://flensed.com flensed Flash+JavaScript browser shims (cross-domain Ajax, cross-browser cookies, etc)]&lt;br /&gt;
&lt;br /&gt;
Rather than getting hung up in the syntax of usage in LABjs that is or is not going to break, it&#039;s best to just think of the problem this way:&lt;br /&gt;
&lt;br /&gt;
Does a site need to load more than one script, at least one of which comes from a remote domain location (like a CDN), and for which among the scripts there&#039;s at least one execution-order dependency among them? If so, then that site is susceptible to the current/future breakage if the HTML spec (and browsers) do not address this use case.&lt;br /&gt;
&lt;br /&gt;
A common example (in use on many sites) of such might be loading:&lt;br /&gt;
&lt;br /&gt;
* jQuery from the CDN&lt;br /&gt;
* jQuery-UI from the CDN&lt;br /&gt;
* plugins and usage code in one or more local files&lt;br /&gt;
* Google Analytics from the Google domain&lt;br /&gt;
&lt;br /&gt;
Note that the emergence of popular script frameworks and their hosting on public CDN&#039;s is leading to more and more sites loading scripts from both local and remote locations, and also to loading more files that have dependencies (rather than the practice of concat&#039;ing all files into one file to avoid dependency issues).&lt;br /&gt;
&lt;br /&gt;
Any site which fits a profile like the above, and which might currently (many do), or in the future want to, use a script loader to improve their loading performance, will fail to achieve what they want cross-browser and in a performant way, if the HTML spec (and browsers) do not address the use case.&lt;br /&gt;
&lt;br /&gt;
=== Benefits ===&lt;br /&gt;
The benefits of addressing both behaviors directly (without &amp;quot;preloading&amp;quot; tricks and bad assumption reliance) have been implied in the above discussion, but in short are:&lt;br /&gt;
&lt;br /&gt;
a) clear and simplified code for script loaders, which leads to easier use by authors of more pages, which in turn leads to better web performance (as demonstrated clearly by intelligent script loading techniques as compared to just simple &amp;amp;lt;script&amp;gt; tags in HTML markup)&lt;br /&gt;
&lt;br /&gt;
b) full access to either/both of the execution-order behaviors (as the author sees fit), regardless of browser&lt;br /&gt;
&lt;br /&gt;
c) avoiding reliance on bad assumptions (like cacheability) as a sufficient way to address the use-case&lt;br /&gt;
&lt;br /&gt;
=== External Discussions of this Feature ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html W3C public-html email thread]&amp;lt;/cite&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://www.w3.org/Bugs/Public/show_bug.cgi?id=11295 W3C Bug #11295]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[https://bugzilla.mozilla.org/show_bug.cgi?id=602838 Mozilla Bug #602838]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[https://bugzilla.mozilla.org/show_bug.cgi?id=620852 Mozilla Bug #620852]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[https://bugs.webkit.org/show_bug.cgi?id=50115 Webkit Bug #50115]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://hsivonen.iki.fi/script-execution/ HTML5 Script Execution Changes in Firefox 4 Beta 7]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://blog.getify.com/2010/10/labjs-w3c-brief-update/ LABjs and W3C... brief update]&amp;lt;/cite&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://blog.getify.com/2010/10/ff4-script-loaders-and-order-preservation/ FF4, script loaders, and order preservation]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proposed Solutions ==&lt;br /&gt;
&lt;br /&gt;
=== My Solution ===&lt;br /&gt;
The current proposal most well supported from the email discussion thread, and the one which I feel makes most sense, is described here.&lt;br /&gt;
&lt;br /&gt;
The HTML spec already defines the &amp;quot;async&amp;quot; attribute for parser-inserted script tags, which when set to &amp;quot;true&amp;quot;, changes their execution order behavior to be like script-inserted script-elements (in IE/Webkit), which is that they load in parallel and execute &amp;quot;as fast as possible&amp;quot; (ostensibly because the author is expressing no dependencies between multiple such &amp;quot;async&amp;quot;-marked scripts). Parser-inserted script elements without &amp;quot;async&amp;quot; (or with it set to false) behave as before and expected, which is that they load in parallel but execute in order.&lt;br /&gt;
&lt;br /&gt;
However, the HTML spec does not define the &amp;quot;async&amp;quot; property (or any such behavior) for script-inserted script nodes (such as those created by a script loader). Instead, the spec implies that &amp;quot;async=true&amp;quot; like behavior is always true for such script-inserted script elements.&lt;br /&gt;
&lt;br /&gt;
What is proposed is:&lt;br /&gt;
&lt;br /&gt;
a) Script-inserted script elements should have (and respect the value of) an &amp;quot;async&amp;quot; property which is basically identical to the &amp;quot;async&amp;quot; attribute for parser-inserted script elements. That is, script elements with the &amp;quot;async&amp;quot; property set to &amp;quot;true&amp;quot; will behave accordingly, as will script elements with the &amp;quot;async&amp;quot; property set to false. &lt;br /&gt;
&lt;br /&gt;
Essentially, the proposal is to mirror the &amp;quot;async&amp;quot; attribute behavior of parser-inserted script elements as an &amp;quot;async&amp;quot; property on script-inserted script elements. This has the benefit of using an existing facility and extending it (from current spec) in a way that is sensisble and symmetric with its current definition.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EFEFEF&amp;quot;&amp;gt;&lt;br /&gt;
The scriptgroup or `readyState`  alternate proposals allow for dependency management to be done in high-level code.  The singular syncrhonized execution queue proposed here introduces artificial dependencies, undermining some of the benefits dynamic script loading provides.  &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #ccc;&amp;quot;&amp;gt;&lt;br /&gt;
It&#039;s important to note that `async=false` scripts will load in a separate queue from `async=true` scripts. It&#039;s not that all scripts will now be forced into this insertion-order-execution queue. An author (or script loader) can chose which queue to put a script loading into based on the needs of the page and the resource. If I have a few scripts that are unrelated to each other and the main page (like Google Analytics, social sharing buttons, etc), I&#039;ll load those via `async=true`. For other scripts, where order matters for dependency sake, I&#039;ll use `async=false`. I think having both those queues available to high-level code is enough control over loading to serve the majority of use-cases pretty well.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EFEFEF&amp;quot;&amp;gt;&lt;br /&gt;
If at any point these services begin dynamically loading `async=false` scripts of their own, they will begin blocking.  This can lead to unexpected behavior of existing code as third-party libraries and services change.  It would seem the specification should provide a means by which this blocking can be isolated to dependencies defined by the author and ordered execution not introduce conditions that allow unrelated libraries to affect this.   &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b) Furthermore, to aid in &amp;quot;feature-detection&amp;quot; of such new behavior, the proposal is to have the default value for the &amp;quot;async&amp;quot; property of script-inserted script elements be &amp;quot;true&amp;quot; (and of course the associated behavior thereof).&lt;br /&gt;
&lt;br /&gt;
There are two major benefits to (b). One is that it provides a way to feature test such new behavior by not just looking for the existence of the &amp;quot;async&amp;quot; property on script elements, but specifically that the default value is &amp;quot;true&amp;quot; (which is opposite of what it would currently/normally be). Secondly, defaulting to &amp;quot;async=true&amp;quot; behavior for script-inserted script elements would preserve the default behavior of IE and Webkit, meaning there&#039;d be less of a chance of breaking existing web content in either of those two browsers.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also important to note that there is no implied or requested effect or dependency between script-inserted script elements and parser-inserted script elements -- the two types of scripts would load and execute in entirely separate behavioral sandboxes.&lt;br /&gt;
&lt;br /&gt;
==== Proposal Amendment: Need Attribute/Property Semantic Inconsistency ====&lt;br /&gt;
In order to achieve consistency between the semantics of how the parser-inserted script element&#039;s `async` attribute and the script-inserted script element&#039;s `async` property behave, a slight change needs to be made to the value parsing/interpretation for parser-inserted script elements&#039; `async` attribute.&lt;br /&gt;
&lt;br /&gt;
If a parser-inserted script element has the `async` attribute present, but its value is exactly &amp;quot;false&amp;quot; (or any capitalization thereof), the script element should behave EXACTLY as if no `async` attribute were present.&lt;br /&gt;
&lt;br /&gt;
If the attribute is present and either has no value, or has any other value except &amp;quot;false&amp;quot; (for instance, &amp;quot;true&amp;quot; or &amp;quot;async&amp;quot;), then it should be interpreted to be turning on &amp;quot;async&amp;quot; for that element.&lt;br /&gt;
&lt;br /&gt;
Because it is highly unlikely (and indeed, quite irrational) that any existing web content is doing `async=&amp;quot;false&amp;quot;` in HTML markup and yet still expecting &amp;quot;async&amp;quot; behavior to be turned on, it is pretty unlikely that this minor interpretation change will cause backwards-compatibility issues.&lt;br /&gt;
[[User:Getify|Getify]] 03:05, 22 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
==== Proposal Amendment: Events ====&lt;br /&gt;
In addition to standardizing how scripts load and execute, it&#039;s also important to standardize the load and error events, and under what circumstances they fire, etc. Without reliable load/error events, the main proposal is not reliable and is thus unhelpful for the use-case.&lt;br /&gt;
&lt;br /&gt;
A script-inserted script element must fire the &amp;quot;load&amp;quot; event only once, when:&lt;br /&gt;
&lt;br /&gt;
a) immediately after the resource finishes loading, but before parsing/execution, AND&lt;br /&gt;
&lt;br /&gt;
b) the script element loads any non-empty content (that is, it was a successful HTTP request), AND&lt;br /&gt;
&lt;br /&gt;
c) the script element has either loaded from the remote location, or is loaded from the brower cache&lt;br /&gt;
&lt;br /&gt;
Specifically, the script &amp;quot;load&amp;quot; event must come immediately between the script element finishing loading and the script element being parsed/executed. If the script resource successfully loads, nothing should interrupt the sequence of fininshing loading, the &amp;quot;load&amp;quot; event firing, and the script being parsed/executed.&lt;br /&gt;
&lt;br /&gt;
A script-inserted script element must fire the &amp;quot;error&amp;quot; event only once, when:&lt;br /&gt;
&lt;br /&gt;
a) immediately after a loading failure for the resource is detected (that is, an HTTP error received, such as 404, 500, 503, etc).&lt;br /&gt;
&lt;br /&gt;
Either the &amp;quot;load&amp;quot; or &amp;quot;error&amp;quot; event, but not both, will fire, and only once, for every script-inserted script element.&lt;br /&gt;
&lt;br /&gt;
NOTE: &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events on script-inserted script elements must fire synchronously to ensure event reliability.&lt;br /&gt;
&lt;br /&gt;
A case may be made for adding the &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events as described here to parser-inserted script elements as well.&lt;br /&gt;
&lt;br /&gt;
==== Processing Model ====&lt;br /&gt;
Script inserted script elements will have an &amp;quot;async&amp;quot; property that defaults to &amp;quot;true&amp;quot;. If the author does not change the value, all such requested script loadings will be in their own &amp;quot;queue&amp;quot; and will default to &amp;quot;as fast as possible&amp;quot; execution behavior. For any script elements that the author sets &amp;quot;async=false&amp;quot;, those scripts will load in a separate &amp;quot;queue&amp;quot;, and will execute in insertion order only. Again, these two &amp;quot;queues&amp;quot; will operate strictly independent of each other.&lt;br /&gt;
&lt;br /&gt;
==== Processing Model Details (without the event amendment) ====&lt;br /&gt;
&lt;br /&gt;
When a script element node is created, if it is being flagged as parser-inserted, set its force-async flag to false. Otherwise, set its force-async flag to true. (Note that createContextualFragment, innerHTML and XSLTProcessor::transformToFragment-created scripts are not flagged as parser-inserted.) This flag setting happens before any attributes (even parser-set ones) are set on the node.&lt;br /&gt;
&lt;br /&gt;
When a previously-created script element node loses its parser-insertedness, if the element doesn&#039;t have the async content attribute, set the force-async flag to true and false otherwise.&lt;br /&gt;
&lt;br /&gt;
When a script element node obtains the async content attribute (via setAttribute, setAttributeNode, setAttributeNS, by the fragment parser or the XSLTProcessor adding the attribute, etc.), set the force-async flag to false. (Note that calling removeAttribute(&amp;quot;async&amp;quot;) doesn&#039;t modify the force-async flag.)&lt;br /&gt;
&lt;br /&gt;
The async IDL attribute must behave as follows:&lt;br /&gt;
* Upon setting, set the force-async flag to false and then reflect the async content attribute.&lt;br /&gt;
* Upon getting, if the force-async flag is true, return true. Otherwise, reflect the async content attribute.&lt;br /&gt;
&lt;br /&gt;
In step 13. of http://www.whatwg.org/specs/web-apps/current-work/#running-a-script before the case &amp;quot;If the element has a src attribute&amp;quot; add a case:&lt;br /&gt;
If the script has a src attribute and the async IDL property getter returns false,&lt;br /&gt;
The element must be added to the queue of ordered script-inserted external scripts of the Document of the script element at the time the running a script algorithm started.&lt;br /&gt;
&lt;br /&gt;
The task that the networking task source places on the task queue once the fetching algorithm has completed must run these steps:&lt;br /&gt;
# If the queue of ordered script-inserted external scripts is empty or the first script in the queue of ordered script-inserted external scripts has not been fetched yet, abort these steps.&lt;br /&gt;
# Execute the first script in the queue of ordered script-inserted external scripts.&lt;br /&gt;
# Remove the first script from queue of ordered script-inserted external scripts.&lt;br /&gt;
# Goto step #1.&lt;br /&gt;
&lt;br /&gt;
Modify step 5 of  http://www.whatwg.org/specs/web-apps/current-work/#the-end to say:&lt;br /&gt;
Spin the event loop until the set of scripts that will execute as soon as possible is empty and the queue of ordered script-inserted external scripts is empty.&lt;br /&gt;
&lt;br /&gt;
==== Limitations ==== &lt;br /&gt;
The two behaviors being identified solve either the case where no dependencies exist, or where a linear dependency chain exists (and which the script elements can be requested to execute in that order). It is possible that some authors have a more complex non-linear dependency chain that they would like to express. This would obviously require a much more complex API and spec change, and since that use-case has not (yet) surfaced as a particularly main-stream request, I believe it would be overengineering to try to address it with this proposed change set.&lt;br /&gt;
&lt;br /&gt;
In addition, it&#039;s been duly noted that it&#039;s undesirable (and potentially confusing/problematic) to intentionally build in the inconsistency of having the &amp;quot;async&amp;quot; attribute (for parser-inserted scripts) and the &amp;quot;async&amp;quot; property (for script-inserted scripts) have different default values (&amp;quot;false&amp;quot; for the attribute, &amp;quot;true&amp;quot; for the property).&lt;br /&gt;
&lt;br /&gt;
It&#039;s also been a point of discussion whether or not such a spec change has enough &amp;quot;carrot&amp;quot; to entice the browser vendors (namely IE and Webkit) to implement the behavior. Moreover, there&#039;s been some concern that if the default value for the &amp;quot;async&amp;quot; property were made to be &amp;quot;false&amp;quot; (like the attribute) to be more consistent and conservative, then it would possibly give the perception to IE and Webkit of &amp;quot;losing&amp;quot; some performance to cut out their default &amp;quot;as fast as possible&amp;quot; behavior.&lt;br /&gt;
&lt;br /&gt;
=== Alternate Proposals === &lt;br /&gt;
One early proposal on the email list was to introduce an entirely new property like &amp;quot;ordered&amp;quot; which an author could add to a script-inserted script element to instruct the browser to put it into the queue of execution-order-preserving script loadings. While such a property would address the use case, it introduces another property and thus more complicates the issue. It also fails to address the current spec inconsistency (which is confusing to new comers) that &amp;quot;async&amp;quot; is not a present/respected property in mirror of the attribute of the same name.&lt;br /&gt;
&lt;br /&gt;
Another suggestion was a &amp;quot;waitFor&amp;quot; property that would be added to script elements and would specify a list of one or more DOM id&#039;s of other script elements that the current script should &amp;quot;wait for&amp;quot; in terms of execution. Again, this would solve the use case, but in a more complicated way, and there are concerns that it would be too confusing for the normal use-case.&lt;br /&gt;
&lt;br /&gt;
Several suggestions have come in the form of creating explicit &amp;quot;preloading&amp;quot; (similar to &amp;amp;lt;link rel=prefetch&amp;gt;), but as described above, &amp;quot;preloading&amp;quot; to solve this use case is a non-ideal hack and highly susceptible to breakage if the script fails to be sent with proper caching headers.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also been suggested that since this type of behavior is somewhat complicated, it may be better to intentionally obfuscate or complicate any such facility in the HTML, so as to make the barrier-to-entry rather high and force users to know what they are doing before doing it.&lt;br /&gt;
&lt;br /&gt;
It&#039;s been suggested that &amp;quot;defer&amp;quot; already preserves execution order. However, &amp;quot;defer&amp;quot; is only defined for parser-inserted scripts, and thus is not applicable to the use-case in question from an on-demand point of view. Also, &amp;quot;defer&amp;quot; scripts explicitly way for DOMContentLoaded, even if they&#039;re ready to execute sooner. So this is less than desired.&lt;br /&gt;
&lt;br /&gt;
Yet another proposal is a &amp;quot;document.executeScripts()&amp;quot; API, where an author can specify multiple sets of scripts that can load in parallel and it will enforce their execution order. A variation on that same idea was to use the &amp;quot;importScripts&amp;quot; from the Web Workers spec, however &amp;quot;importScripts&amp;quot; is synchronous (undesirable performance wise, obviously). The main downside (besides extra API complication) to &amp;quot;document.executeScripts()&amp;quot; is that there seem to be quite a few script execution properties/behaviors (including &amp;quot;document.currentScript&amp;quot; and charset override) which would have to be duplicated into this API facility.&lt;br /&gt;
&lt;br /&gt;
==== &amp;quot;Script Group&amp;quot; element ====&lt;br /&gt;
One recent alternate proposal bears some special consideration, as it seems like it might be a decent option (although certainly more of a radical change for the spec and for browsers to implement). But it has the appearance of being pretty straightforward and semantic for authors to use, perhaps even more so than using &amp;quot;async&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The proposal is to create a new HTML element, called perhaps &amp;amp;lt;scriptGroup&amp;gt;, &amp;amp;lt;collection&amp;gt;, etc. Specifically, this element must be able to be inserted wherever a &amp;amp;lt;script&amp;gt; element can currently be inserted. The &amp;quot;script group&amp;quot; element is intended to signify that all script elements added to it must perserve insertion execution order. This element wouldn&#039;t have much (but still some, explained in a moment) meaning in a parser-inserted context, since parser-inserted scripts already preserve order among themselves.&lt;br /&gt;
&lt;br /&gt;
An advantage of the &amp;quot;script group&amp;quot; element would be to give a direct and easy way to attach event listeners (&amp;quot;load&amp;quot; and &amp;quot;error&amp;quot;) to the entire group, rather than having to internally track events for each element if all you care about is the final &amp;quot;load&amp;quot; event, for instance. In the case of event handling, the &amp;quot;script group&amp;quot; element would have perhaps some benefit even in parser-inserted (markup) context.&lt;br /&gt;
&lt;br /&gt;
The element would need to have an &amp;quot;id&amp;quot; property, and possibly attributes for &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events.&lt;br /&gt;
&lt;br /&gt;
A variation on how to look at this proposal is that a &amp;quot;script group&amp;quot; element could have an attribute/property on it (perhaps called &amp;quot;ordered&amp;quot;) which would allow the group to either be order preserved or not. This would make the &amp;quot;script group&amp;quot; element much more useful in the parser-inserted context, as it would sort of be a shortcut to setting &amp;quot;async=true&amp;quot; on all the child script elements.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;script group&amp;quot; element might look like this:&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group1&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;foo.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;bar.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      somethingInline();&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, with the &amp;quot;ordered&amp;quot; attribute to explicitly control ordering behavior for the group:&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group1&amp;quot; ordered=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;foo.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;bar.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      somethingInline();&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group2&amp;quot; ordered=&amp;quot;false&amp;quot; onload=&amp;quot;alldone();&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;baz.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;far.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;zab.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the &amp;quot;script group&amp;quot; element is definitely more complicated to define and implement, it does have some semantic advantages for authors, and it also would significantly reduce the internal complexity of script loaders like LABjs. It would give authors (either directly or through script loaders) the flexibility to group scripts together into one of the two aforementioned behaviors (execution &amp;quot;as fast as possible&amp;quot; or &amp;quot;in insertion order&amp;quot;), and to easily access both behaviors in the same page.&lt;br /&gt;
&lt;br /&gt;
==== Explicit support for &amp;quot;text/cache&amp;quot; MIME type behavior ====&lt;br /&gt;
Yet another alternate proposal has been suggested in the [[Talk:Dynamic_Script_Execution_Order]] thread. &lt;br /&gt;
&lt;br /&gt;
Essentially, the proposal is that &amp;amp;lt;script&amp;gt; tags directly support being declared with a `type` value of &amp;quot;text/cache&amp;quot;. The behavior would be that the script resource is fetched, as the load events fired, as normal, but that the script itself would not be executed. Then later, at the desired time, the script in that element could be executed by changing the `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The browser would probably need to keep track (via some internal flag) that the script node is only ever executed once. Also, it&#039;s an open question if such a &amp;quot;cached&amp;quot; script node should be able to have its script content modified before execution via the `text` property.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
And does the onload event fire again after the script executes?  &amp;lt;br/&amp;gt; &lt;br /&gt;
Or only when it&#039;s loaded? &amp;lt;br/&amp;gt; &lt;br /&gt;
Both seem to violate current `onload` semantics.  &lt;br /&gt;
[[User:Serverherder|Serverherder]] 20:27, 15 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#ccc&amp;quot;&amp;gt;&lt;br /&gt;
As far as I&#039;m concerned, I think the &amp;quot;load&amp;quot; event should happen immediately after a script loads, but before it executes, as I spell out in the [[Dynamic_Script_Execution_Order#Proposal_Amendment:_Events|Events proposal ammendment section]]. [[User:Getify|Getify]] 20:33, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== readyState &amp;quot;preloading&amp;quot; ====&lt;br /&gt;
Per the suggestion/comment added to the above [[Dynamic_Script_Execution_Order#Current_Limitations|Current Limitations]] section, it&#039;s been suggested that IE&#039;s current behavior with respect to the `readyState` property can adequately serve the use-case in question. This alternate proposal is very similar in spirit to the [[Dynamic_Script_Execution_Order#Explicit_support_for_.22text.2Fcache.22_MIME_type_behavior|previous section on explicit support for &amp;quot;text/cache&amp;quot;]] mime-type value.&lt;br /&gt;
&lt;br /&gt;
The idea is that IE will begin fetching into the cache a script resource as soon as the `src` attribute of the dynamic script element is set. But IE will not execute the script (even if it finishes loading) until the script element is added to the DOM. However, the `readyState` property of the element, combined with the `onreadystatechange` handler listening for changes, can detect when the script has finished loading, by receiving the &amp;quot;loaded&amp;quot; value.&lt;br /&gt;
&lt;br /&gt;
In this way, a script loader could &amp;quot;preload&amp;quot; a set of scripts all in parallel, but control their execution order by delaying the appending of the element to the DOM until execution is desired.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Update&#039;&#039;&#039; [[User:Getify|Getify]] 14:10, 20 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
[http://www.w3.org/TR/html5/scripting-1.html#running-a-script HTML Spec, 4.3.1, &#039;Running a script&#039; algorithm]&lt;br /&gt;
&lt;br /&gt;
Specifically, in step 12 (which is about fetching a `src` URL):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
For performance reasons, user agents may start fetching the script as soon as the attribute is set, instead, in the hope that the element will be inserted into the document. Either way, once the element is inserted into the document, the load must have started. If the UA performs such prefetching, but the element is never inserted in the document, or the src attribute is dynamically changed, then the user agent will not execute the script, and the fetching process will have been effectively wasted.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This seems to be the spec stating that browsers may do what IE&#039;s behavior on scripts does, which is to start fetching the resource once the `src` property is set, but not execute it until the script element is inserted into the DOM.&lt;br /&gt;
&lt;br /&gt;
It would seem then that browsers could/should be petitioned to consider implementing this suggestion, perhaps taking the `readyState` implementation from IE as guidance. While I&#039;m still not sure that this would be my preferred method of solving the overall use-case in discussion on this page, it would be an option for such, and it would also help other use-cases, such as those being discussed in this W3C public-html thread:&lt;br /&gt;
&lt;br /&gt;
[http://lists.w3.org/Archives/Public/public-html/2010Dec/0174.html Need to: &amp;quot;preload&amp;quot; CSS and JS]&lt;br /&gt;
&lt;br /&gt;
==== Do nothing and encourage vendors implement the existing suggestion ====&lt;br /&gt;
As noted by Getify above, the spec all ready makes the suggestion that a script&#039;s SRC attribute be fetched immediately upon assignment.  &lt;br /&gt;
&lt;br /&gt;
[http://www.w3.org/TR/html5/scripting-1.html#running-a-script HTML Spec, 4.3.1, &#039;Running a script&#039; algorithm]&lt;br /&gt;
&lt;br /&gt;
While not explicit, it seems the specification all ready deals with the use-case this is hoping to achieve: It makes parallel loading scripts &#039;&#039;&#039;optional&#039;&#039;&#039;.   Execution order can all ready be handled by loaders using onload-chaining.  Therefore, parallel loading can be achieved, but only in browsers that have chosen to implement the suggestion. &lt;br /&gt;
&lt;br /&gt;
Given this, the discussion can shift to: &lt;br /&gt;
# Should the suggestion be changed to a mandate? &lt;br /&gt;
# Should the specification include a way to &#039;&#039;&#039;force&#039;&#039;&#039; parallel loading? &lt;br /&gt;
# Should we be petitioning vendors, not the the W3C, to implement the existing suggestion? &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Feature Request|Dynamic Script Execution Order]]&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5630</id>
		<title>Talk:Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5630"/>
		<updated>2010-12-16T01:52:49Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* RequireJS order support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please discuss the proposal here. All informal feedback is welcomed, and when it&#039;s appropriate, please add content to the main page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What about CommonJS / RequireJS? ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m not sure we need to complicate the HTML or browser engines in order to satisfy the advanced use cases.  To me it seems that the JavaScript langauge itself could abstract the requirements and let the browser vendors implement whatever solution they see fit.  Specifically, if JavaScript provided the define() and require() calls proposed in the CommonJS &amp;quot;specifications&amp;quot; (and implemented by [http://requirejs.org/docs/api.html RequireJS], [http://svn.dojotoolkit.org/src/dojo/trunk/_base/_loader/loader.js dojo (trunk)], and others *Yabble?), then browsers could just load and evaluate scripts as fast as possible without regard to script execution order.  &lt;br /&gt;
&lt;br /&gt;
This would solve all of the problems except for the current inability to use loaders like LABjs in FF4 or webkit.  To solve that problem, we should consider keeping the existing functionality or triggering the deprecated functionality when needed.&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
=== Response ===&lt;br /&gt;
&lt;br /&gt;
This is a valid point except that it assumes that all code that needs to be loaded is &amp;quot;modular&amp;quot;... in fact, most code on the internet that needs to be loaded is NOT modular, and instead requires particular ordering when being loaded... for instance, &amp;quot;jquery&amp;quot; and &amp;quot;jquery-ui&amp;quot; -- jQuery must be run before jQuery-UI is loaded and run.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The spirit of this proposal is to add the facility to native browser (rendering engine, specifically) behavior, such that any and all existing content is able to be loaded (even with dependencies and order) without modification.&lt;br /&gt;
&amp;lt;blockquote style=background-color:#eee&amp;gt;&lt;br /&gt;
Are we trying to codify how one would implement this HTML dynamically so I can achieve parallel loading but retain dependency that is inferred in the order? &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: white&amp;quot;&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery-ui.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If so, we must consider the case in which the dependency itself loads additional code which the discussions around `async=false` or even text/cache do not account for.  &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:23, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dependent code should be modular ===&lt;br /&gt;
&lt;br /&gt;
I completely agree, 99% of JavaScript in use today is NOT modular, but that&#039;s arguably because there was no built-in support to make it modular (IMHO, YMMV, RTFM, BBQ, ROFL).  But that doesn&#039;t mean there aren&#039;t dependencies that span script files / script nodes.  I don&#039;t know how many sites would be broken (or if there is any way to determine how many sites would be broken) if/when the latest browsers started loading and evaluating script-injected scripts out of order.  It&#039;s not just LABjs-based sites.  I&#039;ll bet many dojo and YUI sites will break, too (although I don&#039;t know this for a fact because I don&#039;t know exactly how their dynamic script loaders work).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;In any case, breaking existing sites is a BAD IDEA. :)  There should be some way to allow LABjs and other dynamic script loaders to continue to work.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The part I don&#039;t agree with in the proposals is that it should be the job of HTML and/or the browser engine to manage dependencies.  Specifically, I am talking about the scriptGroup element and the &amp;quot;waitFor&amp;quot; attribute.  The &amp;quot;async&amp;quot; attribute may be the right level: it appropriates only general heuristics to the browser: &#039;&#039;load these scripts whenever you like, but load these other scripts in this order&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Detailed dependency management belongs in the modules, though.  This is how it&#039;s done in most environments / languages: import statements, include statements, etc.  It&#039;s no different in JavaScript, if a developer wants to take advantage of some code in another module, she/he should import it into their current module.  This should be the model moving forward.  It&#039;s not hard, it&#039;s not un-web-like, and it&#039;s already being done.  &lt;br /&gt;
&lt;br /&gt;
Existing code can be made to work modularly, too:&lt;br /&gt;
&lt;br /&gt;
1. Identify modules and wrap them with a define() method.&lt;br /&gt;
2. Identify dependencies using either the [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition Asynchronous Module Definition] format or the CommonJS synchronous format&lt;br /&gt;
&lt;br /&gt;
async format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define([&#039;dependency1&#039;, &#039;dependency2&#039;], function (dependency1, dependency2) {&lt;br /&gt;
	/* this is the factory function, return the module inside here */&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sync format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define(function (require, exports, module) {&lt;br /&gt;
	/* this is the factory function, require dependencies and return the module inside here */&lt;br /&gt;
	var dependency1 = require(&#039;dependency1&#039;);&lt;br /&gt;
	var dependency2 = require(&#039;dependency2&#039;);&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the async case, the browser may employ whatever method it sees fit (e.g. parallel) to download the dependencies since the code inside the factory function won&#039;t execute until all of the dependencies are loaded and evaluated.  In the sync case, the browser has no choice but to download and evaluate the dependency before continuing code execution.  It&#039;s conceivable that the browser could find and asynchronously pre-fetch the inline require()&#039;ed dependencies in the sync case.  (RequireJS doesn&#039;t quite do this.  Instead I believe it finds the inline require() calls and converts the module to an async module.)  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;So, in short: don&#039;t break LABjs (or any other script loaders), but don&#039;t extend the spec to manage dependency management from HTML.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Response #2 ==&lt;br /&gt;
&lt;br /&gt;
The cat&#039;s already out of the bag... we&#039;ve got a dozen+ years worth, hundreds of millions of javascript files out there, which are NOT modular, and will not be modified to be modular. &lt;br /&gt;
&lt;br /&gt;
If we&#039;re talking about either trying to change all the JS on the web to be modular, or trying to extend the HTML markup spec to include a better facility for accomodating the existing script content, I think the former is idealistic and &amp;quot;correct&amp;quot; but the latter is realistic and &amp;quot;right&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
A modular loading system will only work for modular code, but a general loading mechanism in HTML (like the &amp;amp;lt;script&amp;gt; tag) can load both modular and non-modular code, which is why that more general mechanism is what&#039;s in HTML right now and not some more specialized loading API that only loads a small percentage of JavaScript code out there.&lt;br /&gt;
&lt;br /&gt;
The &amp;amp;lt;script&amp;gt; tag has worked fine forever, and there&#039;s been no real big push to do away with it in favor of having all loading handled by JavaScript -- in fact, that would be impossible because if you had no way to load JS onto the page with a &amp;amp;lt;script&amp;gt; tag, then no JavaScript could run on a page to load more code. So I don&#039;t agree that we should stop adding functionality to the HTML loading mechanism and only focus on JavaScript.&lt;br /&gt;
&lt;br /&gt;
If we agree that the &amp;amp;lt;script&amp;gt; tag itself is not only required but normative, then I&#039;m not sure why decorating the &amp;amp;lt;script&amp;gt; tag with additional behavior to help it be more powerful is a bad pattern. We&#039;ve addded &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; already. I&#039;m not sure I understand why adding a wrapper tag called &amp;quot;scriptGroup&amp;quot; would be that much different than attributes on the &amp;amp;lt;script&amp;gt; tag?&lt;br /&gt;
&lt;br /&gt;
I also don&#039;t think that &amp;quot;scriptGroup&amp;quot; constitutes &amp;quot;dependency management&amp;quot;. &amp;quot;scriptGroup&amp;quot; is a semantic way for a web author to express that they want to group a set of scripts together ONLY so far as execution order behavior is concerned. It implies nothing more to it (that &amp;quot;dependency management&amp;quot; would imply) than that.&lt;br /&gt;
&lt;br /&gt;
For instance, consider this: if JavaScript had been built with non-global context and statement level context and sandboxing and such things, we&#039;d have a much more secure JavaScript right now. But just because JavaScript may someday be taught some new tricks in terms of security, that doesn&#039;t mean that &amp;quot;now&amp;quot; HTML shouldn&#039;t try to help solve the problem. If for instance the &amp;amp;lt;frag&amp;gt; tag can be used to create a sandboxed environment for third-party JavaScript code to run in, this is a much easier way to address the security problem than to suggest we have to wait for ES-Harmony to add extra syntax to the language to accomplish the same thing.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 02:13, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Text/cache solution ==&lt;br /&gt;
&lt;br /&gt;
It seems to me that having a real text/cache script type, or a similar element that fires a load/error event and provides a .text property gets you where you need to be. You could setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/JavaScript&amp;quot;) or use the text to create a new script element. Or a new style element, or whatever. That puts you in control of when script or CSS is interpreted. With async as the default, you don&#039;t need a new ordered attribute as that&#039;s easily managed in script.&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;text/cache&amp;quot; response ==&lt;br /&gt;
&lt;br /&gt;
On the surface, this idea sounds like it&#039;s pretty similar to &amp;amp;lt;link rel=prefetch&amp;gt; -- in other words, we&#039;ve already standardized a way to prefetch a resource into cache, and probably in a better way than the hack that I did in LABjs of just relying on it fetching unrecognizable content.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it still suffers some similar problems to &amp;amp;lt;link rel=prefetch&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Firstly, if the notion is that you&#039;d use &amp;amp;lt;script type=&amp;quot;text/cache&amp;quot;&amp;gt; to prefetch, and then you&#039;d make a second request for the resource with a real &amp;amp;lt;script type=&amp;quot;text/javascript&amp;gt; node, it suffers the faulty assumption that the resource was served with proper cache headers.&lt;br /&gt;
&lt;br /&gt;
If we try to avoid the need for the second request by suggesting that you can access the `text` property of the node (and then eval() or inject that code when you want to execute it), this runs afoul of the same-origin policy problem if you requested the script from a non-local domain.&lt;br /&gt;
&lt;br /&gt;
The part of your suggestion that holds water would be if, given a &amp;quot;prefetched&amp;quot; script node that didn&#039;t execute yet, I could simply change that node&#039;s `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;, and that would explicitly trigger the browser to immediately execute it. &lt;br /&gt;
&lt;br /&gt;
This is an interesting idea. I can see though that it perhaps has some potential complications. &lt;br /&gt;
&lt;br /&gt;
For instance, would the browser have to keep a &amp;quot;hasExecuted&amp;quot; internal flag, so that changing the `type` value would only at most result in one execution? Also, if the script node in question is loaded but not executed, can the page alter the script code (by setting its `text` property) before making the change to the `type` value? In that case, should the browser execute the original code or the modified code? I can see security implications and confusion abounding in that behavior.&lt;br /&gt;
&lt;br /&gt;
Lastly, as mentioned above, this basically copies (in a similar but not exactly identical way) the &amp;amp;lt;link rel=prefetch&amp;gt; behavior. It may be seen as a negative to be trying to step on the toes of &amp;amp;lt;link rel=prefetch&amp;gt;, and also it may be more confusing to the general public as to why you&#039;d use one technique or the other, given their differences being so nuanced.&lt;br /&gt;
&lt;br /&gt;
That having been said, I can see that it&#039;s a viable alternate proposal. It&#039;s worth adding a note to that section of the main Wiki page and to getting some feedback from browser vendors on if they feel this is a more realistic/suitable solution to the use-case.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #eee&amp;quot;&amp;gt;&lt;br /&gt;
The difference between pre-fetching and this proposal seems pretty clear: Prefetching, if not performed now, will eventually be done once the user explicitly requests the page. while the &amp;quot;text/cache&amp;quot; solution indicates that the resource should load &#039;&#039;&#039;immediately&#039;&#039;&#039;, not during idle time. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:10, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 20:56, 4 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== RequireJS order support ==&lt;br /&gt;
&lt;br /&gt;
I am the main developer for RequireJS, and just want to voice my support for a solution that works on the script element itself, either by leveraging the async attribute or allowing something like an &amp;quot;order&amp;quot; boolean attribute that would allow specifying a dynamically added script element should be executed in the order that it appears in the DOM. This capability should be something can be capability detected to avoid browser sniffing.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Why shouldn&#039;t dependency management be implemented in high-level code and the browser simply provide a means by which parallel loading can be achieved?  As you know, there is a considerable amount of nuance.  I&#039;m of the opinion that implementing dependency management in the engine will eventually lead us right back to where we were 10 years ago with inline script tags which provides an easy method for dependency management at the expense of unmanaged blocking and an inability to detect or adapt to errors. &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
There are many scripts on the web today that have implicit dependencies that should be loaded in a specific order, but the application developer will want to use dynamically created script elements for best performance. jQuery plugins that depend on the jQuery script already been executed in the page are a good example.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Agreed, but I don&#039;t believe the proposals allow for proper emulation of the dependency management provided by script tags.  Prototype.js, for example, loads its core modules dynamically (using document.write so maybe not the best example...).  When prototype.js is included via script tags, ensuing script blocks are free to &amp;quot;depend&amp;quot; on all of these modules; Dynamically creating a dependency on prototype.js by loading both with the `async=true` property will fail since prototype.js won&#039;t be able to &amp;quot;jump the queue&amp;quot; and add insure its core modules load before its extensions.  &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#ccc&amp;quot;&amp;gt;&lt;br /&gt;
I have to admit, you raise a valid point with respect to that common usage. The YUI model (where the framework is responsible for all loading) is perhaps the more appropriate model to move toward, though. Or, the framework doesn&#039;t auto-load its own dependencies at all. In either case, I think it&#039;s cleaner to have one loading mechanism in play rather than two or more competing ones, because as you point out, this is going to get messy. I still am not sure this means that the async=false proposal is lacking, because as I think about how complicated such a split loading would be with your `readyState` proposal, that seems even worse/more complicated to me. [[User:Getify|Getify]] 20:06, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
I would not argue &#039;&#039;&#039;against&#039;&#039;&#039; a global queue for synchronized execution, I just think the usefulness of such a construct declines as scripts that &amp;quot;I don&#039;t care about&amp;quot; are added.  It&#039;s my opinion the spec should provide the ability for high-level code to implement similar constructs, regardless of how complex it may be to do so. &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
That being said, I don&#039;t think it&#039;s any more complicated than existing models.  Here&#039;s a demonstration of an [http://digital-fulcrum.com/executionorder/ IE-only parallel-loading, synchronously-executing script queue] implemented in 40 lines of code.  It tests both cached and un-cached scripts (from the LABjs test suite) and has been tested and found to be working in IE6-8. &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[User:Serverherder|Serverherder]] 01:52, 16 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
- James Burke&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Dynamic_Script_Execution_Order&amp;diff=5628</id>
		<title>Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Dynamic_Script_Execution_Order&amp;diff=5628"/>
		<updated>2010-12-15T20:27:22Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* Explicit support for &amp;quot;text/cache&amp;quot; MIME type behavior */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is intended to formalize the discussion around an important but currently underserved use-case (in both spec and various browser implementations): the need for a dynamic script loading facility that can download resources in parallel but ensure that they execute serially in insertion order, for dependency reasons.&lt;br /&gt;
&lt;br /&gt;
A long email thread on the W3C public-html list, which began [http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html here] and for which a recent message is [http://lists.w3.org/Archives/Public/public-html/2010Oct/0415.html here], has been discussing this problem, but the email thread is becoming unruly and hard to track, so this wiki page will now be the official location to discuss the topic.&lt;br /&gt;
&lt;br /&gt;
Briefly, this issue has arisen because recent &amp;quot;nightlies&amp;quot; changes in both Mozilla Gecko and Webkit have broken the ability for script-loaders like [http://labjs.com LABjs] to be able to download scripts in parallel but ensure their execution order. As a result of the discussion, it&#039;s become apparent that both the spec for, and various current browser implementations around, dynamic script loading is incomplete in addressing this use case, and that some change needs to occur.&lt;br /&gt;
&lt;br /&gt;
There is one main proposal that has surfaced from the discussions, with several other alternatives having been discussed. This page will try to distill the long email thread down and clearly present the main proposal, objections, and alternative suggestions.&lt;br /&gt;
&lt;br /&gt;
Please feel free to join the discussion of this topic in the [[Talk:Dynamic_Script_Execution_Order]] area.&lt;br /&gt;
&lt;br /&gt;
== Use Case Description ==&lt;br /&gt;
Script tags/elements can either: &lt;br /&gt;
&lt;br /&gt;
a) appear in the HTML markup (&amp;quot;parser-inserted&amp;quot;), OR&lt;br /&gt;
&lt;br /&gt;
b) be dynamically appended to the DOM using document.createElement() (&amp;quot;script-inserted&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Parser-inserted script tags, up until recent browser versions, had the undesirable performance behavior of loading and executing serially, blocking everything else while doing so. Recently, many browsers have improved the situation by loading the scripts in parallel, but still executing them in order.&lt;br /&gt;
&lt;br /&gt;
On-demand (or dynamic) script loading has emerged in recent years for a variety of different reasons, most notably the performance improvements to address such concerns. It is desired by many different scenarios to be able to download scripts to a page completely independently of the loading of the rest of a page&#039;s resources, or even well after a page has finished loading (&amp;quot;on-demand&amp;quot;).  &lt;br /&gt;
&lt;br /&gt;
Recent additions to HTML spec such as &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; were intended to address the use-case for parser-inserted script elements, but their behaviors have been unhelpful for the on-demand loading use-case (script-inserted script elements).&lt;br /&gt;
&lt;br /&gt;
Thus, script loaders (like [http://labjs.com LABjs]) were developed to give page authors an easy way to specify one or more scripts to load (regardless of when in the life-time of the page that loading is requested), and for as many of them as possible to load in parallel, and for those scripts to be loadable from any local or remote domain location, and for the script loader to be able to control the execution order (if the usage of the script loader&#039;s API expresses the need to) to preserve dependencies between the scripts.&lt;br /&gt;
&lt;br /&gt;
Sometimes, dynamic script loading is used to load totally independent scripts, and thus &amp;quot;as fast as possible&amp;quot; execution is desired. Other times (and possibly more frequently), multiple scripts are loaded with some  dependencies among them, requiring them to execute in a certain order. &lt;br /&gt;
&lt;br /&gt;
What is needed is some facility by which a script loader can express that dynamic script loading either does or does not need execution order preserved among the queue of requested script loadings.&lt;br /&gt;
&lt;br /&gt;
=== Current Limitations ===&lt;br /&gt;
Unfortunately, browser behavior around script-inserted script elements and their loading and execution behavior is splintered. There are, at present, two main camps of behavior:&lt;br /&gt;
&lt;br /&gt;
a) in IE and Webkit (including Chrome), the default behavior for script-inserted script elements is for them all to execute in &amp;quot;as fast as possible&amp;quot; mode, meaning there&#039;s no guarantee about ordering. This effectively makes on-demand (dynamic) script loading impossible to work in parallel-mode if the resources in question have dependencies -- the only straight-forward way to handle things is to load each file and execute, serially, losing the parallel loading performance benefits.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
I&#039;m not sure if this is the case.  &lt;br /&gt;
&lt;br /&gt;
IE will start fetching resources without execution simply by setting the src attribute.  Scripts will not execute, however, until they are added to the document.  Since IE supports the readyState attribute and readystatechange event, it&#039;s possible to load scripts in parallel and execute them in order without resorting to invalid type attribute hack-ery.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:white&amp;quot; lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
script= document.createElement(&amp;quot;SCRIPT&amp;quot;); &lt;br /&gt;
script.onreadystatechange= function(){ &lt;br /&gt;
    if(this.readyState == &#039;loaded&#039;)&lt;br /&gt;
          /* &lt;br /&gt;
             Network fetch is now complete, following&lt;br /&gt;
             triggers synchronous execution.  &lt;br /&gt;
          */&lt;br /&gt;
          document.body.appendChild(this); &lt;br /&gt;
    else if(this.readyState == &amp;quot;complete&amp;quot;)&lt;br /&gt;
          this.onreadystatechange= null; &lt;br /&gt;
}&lt;br /&gt;
script.src= &amp;quot;foo.js&amp;quot;; &lt;br /&gt;
/* Network fetching begins now */&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #ccc&amp;quot;&amp;gt;&lt;br /&gt;
I&#039;ve experimented with such things heavily in the past, and I&#039;m fairly suspicious that this is not reliable across various versions of IE (6-9), nor does it work reliably the same depending on if an element is already in the browser cache or not. I&#039;m not 100% certain that what you suggest is flawed, but I have a strong hunch that it can be shown to have some holes in it for IE loading. I will try to create some test cases to prove or disprove.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
When loading a script that is in the cache, IE requires the event handler be installed prior to setting the `src` attribute.  Otherwise the element&#039;s transition to the &amp;quot;loaded&amp;quot; state will be missed.  IE routinely &amp;quot;skips&amp;quot; ready state transitions when cached scripts are immediately inserted into the DOM so suspicion is understandable; however, delayed insertion works around this &amp;quot;problem&amp;quot;.  The script above has been tested in IE6-8 with scripts in a variety of caching states and found to work correctly. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Moreover, you&#039;re suggesting something that is AFAIK only IE right now, and definitely appears to not be standardized. In the same way that I&#039;m hesitant to continue pinning loading behavior on hacks like the invalid type attribute value, I wouldn&#039;t want to approach loading with this technique (even if it were proven reliable on all IE&#039;s under all caching circumstances) unless it was a serious proposal to the W3C to have this technique be the new standard (as opposed to the current proposal, as implemented by Mozilla and Webkit now).&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
I think you&#039;re right: Only IE impelements this event and property on script elements.  The readystatechange event, however, is widely understood due to the XmlHttpRequest implementation and `readyState` property has been added to the `document` in WebKit, Mozilla and IE. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
That having been said, I think this is at least a viable candidate for &amp;quot;Alternate Proposals&amp;quot; and deserves to be listed as such. As always, I welcome input from the community on all the ideas presented here, including this one. But, since the main proposal (async=false) is already being implemented by at least two major browsers, I&#039;m not sure if the tide will be changed or not.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#ddd;&amp;quot;&amp;gt;&lt;br /&gt;
Also, the suggestion of handling the &amp;quot;preload&amp;quot; and deferred execution via the script tag&#039;s `readyState` property is very similar in spirit to the suggestion that was made to explicitly support [[Dynamic_Script_Execution_Order#Explicit_support_for_.22text.2Fcache.22_MIME_type_behavior|preloading into cache without execution]]. As I said, either of those two approaches might work, but they both put more of the onus of complexity in managing multiple dependencies on the high-level code (author, script loader, etc). I&#039;m more in favor of this functionality being explicitly built-in natively into the queues. As always, I welcome comments to any side of this discussion.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 18:35, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
b) in Gecko and Opera, the default behavior for script-inserted script elements is for them all to load in parallel, but execute serially in insertion order. Technically, this makes it impossible to dynamically load independent script elements and have them execute in &amp;quot;as fast as possible&amp;quot; mode.&lt;br /&gt;
&lt;br /&gt;
As described above, both behaviors are desirable under different circumstances, but each of the two camps provides only one behavior, and no way to straightforwardly achieve the other. This obviously creates a big nightmare interoperability-wise when trying to provide a general script loader cross-browser.&lt;br /&gt;
&lt;br /&gt;
Since it is observed that the behavior in (a) is more detrimental (race-condition wise) for the case where dependencies exist, script loaders like LABjs had to find some way around this problem while still attempting the best possible parallel loading performance. However, the trick used is hacky and not completely reliable -- yet it is the best way to solve the use-case in &amp;lt;s&amp;gt;IE and &amp;lt;/s&amp;gt;Webkit. &lt;br /&gt;
&lt;br /&gt;
For Gecko/Opera, the concession was just (silently) made that the lesser-common use case of &amp;quot;as fast as possible&amp;quot; wasn&#039;t possible, but degraded fine to &amp;quot;insertion order execution&amp;quot;, while keeping the parallel loading benefits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
Gecko&#039;s strict execution order creates dependencies between scripts which are unrelated and prevents the ability mitigate the impact of server outages / network latency.  This is exacerbated by the fact that Gecko, unlike IE and WebKit, provides no mechanism to &amp;lt;b&amp;gt;remove&amp;lt;/b&amp;gt; scripts from the execution queue. &lt;br /&gt;
&lt;br /&gt;
Consider the case where JSONP is used to provide auto-completion.  The user types &amp;quot;hello&amp;quot; and the JSONP request is made; however, the &amp;quot;currently&amp;quot; loading script is out-of-date as soon as the user modifies his search to &amp;quot;hello world&amp;quot;.  Gecko&#039;s algorithm requires the out-of-date request load and execute before the second request.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Recently, Gecko landed a [http://hg.mozilla.org/mozilla-central/rev/a60414d076b5 patch] to the trunk that stopped Gecko&#039;s existing behavior of preserving execution order, making script-inserted script elements now execute in &amp;quot;as fast as possible&amp;quot; mode similiar to IE/Webkit. Unfortunately, the &amp;quot;workaround&amp;quot; used in IE/Webkit (described in the next section) for dealing with parallel loading and execution-order dependencies does not work in Gecko, which means presently the use-case in question is now broken in Gecko trunk/FF4 nightlies.&lt;br /&gt;
&lt;br /&gt;
Moreover, Webkit recently landed a [http://trac.webkit.org/changeset/67245 patch] to the trunk that stopped Webkit&#039;s non-standard but long-held behavior (also used in the &amp;quot;workaround&amp;quot; described in the next section) of loading into cache script resources with an unrecognized &amp;quot;type&amp;quot; value, but silently not executing them. This behvaior (while hacky) is central to being able to address the use-case in question in Webkit, so at present, Webkit nightlies are now also entirely broken on the use-case (though in a different way than Gecko).&lt;br /&gt;
&lt;br /&gt;
Both the Gecko change and the Webkit change are well-intentioned, as they are bringing the respective browser more in line with the HTML spec. However, what&#039;s really been demonstrated is that the HTML spec is not properly handling this use-case, and so the goal is not to address the browser issues raised with more awkward hacks, but to address the shortcomings of the spec first, and then encourage all browsers to adhere to such.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
Considering Internet Explorer&#039;s readyState implementation provides a means of both parallel loading and preserving execution order can be achieved, perhaps its &amp;quot;readyState&amp;quot; property and onreadystatechange event should be included. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Current Usage and Workarounds ===&lt;br /&gt;
To work around the limitation in IE/Webkit(prior to the above noted patch) of not being able to rely on script order execution for parallel loaded scripts, a &amp;quot;preloading&amp;quot; trick was developed. This trick relied on non-standard (but long-held) behavior in these browsers that a script-inserted script element with an unrecognized &amp;quot;type&amp;quot; value (such as &amp;quot;script/cache&amp;quot;) would be fetched/loaded, but would not execute. This had the effect of loading the resource into cache, and then firing the &amp;quot;load&amp;quot; handlers to let the page know when the resource was completely in cache. &lt;br /&gt;
&lt;br /&gt;
Assuming that the resource was served with proper caching headers, and was in fact in the cache, it could then be executed (nearly) immediately when it was the proper execution order time by re-requesting the same resource via another script-inserted script element with the proper &amp;quot;text/javascript&amp;quot; type value, pulling the resource from the cache and executing it, without another server round-trip.&lt;br /&gt;
&lt;br /&gt;
Of course, the assumption of proper cache headers is a huge one, and not at all reliable. Some recent estimates by performance optimization specialists have suggested as much as 70% of scripts across the internet are not served with proper caching headers, which means that such scripts would be completely ineffective if loaded using this (or a similar) technique. The script resource would end up being loaded completely a second-time, and the &amp;quot;near immediate&amp;quot; execution would obviously be false, and thus race conditions would ensue.&lt;br /&gt;
&lt;br /&gt;
It&#039;s important to note at this point that the new &amp;amp;lt;link rel=prefetch&amp;gt; facility has been suggested as a better workaround, but it suffers the same ill-fated assumption of script cacheability. Still others have suggested &amp;quot;new Image().src=...&amp;quot; or the [http://www.phpied.com/preload-then-execute/ &amp;amp;lt;object&amp;amp;gt; preloading trick] suggested by Stoyan Stefanov. Again, these tricks unwisely assume cacheability, for the &amp;quot;preloading&amp;quot; trick to solve the use-case in question.&lt;br /&gt;
&lt;br /&gt;
=== At Risk ===&lt;br /&gt;
Currently, there are several large/popular web sites which are either currently (or who intend to soon) use LABjs in such a way as to run afoul of the new Gecko and Webkit behavioral changes with LABjs failing to operate properly. It&#039;s important to note that the problems of race conditions can be subtle and hard to detect, and so merely loading up such sites and failing to observe overt failure is not sufficient.&lt;br /&gt;
&lt;br /&gt;
Sites which are known to have LABjs loading techniques in place with currently broken (or susceptible to such breakage in the near future) behavior are:&lt;br /&gt;
&lt;br /&gt;
* [http://twitter.com Twitter]&lt;br /&gt;
* [http://zappos.com Zappos]&lt;br /&gt;
* [http://vimeo.com Vimeo]&lt;br /&gt;
* [http://mefeedia.com MeFeedia]&lt;br /&gt;
* [http://blog.getify.com Getify Solutions blog (my blog)]&lt;br /&gt;
* [http://flensed.com flensed Flash+JavaScript browser shims (cross-domain Ajax, cross-browser cookies, etc)]&lt;br /&gt;
&lt;br /&gt;
Rather than getting hung up in the syntax of usage in LABjs that is or is not going to break, it&#039;s best to just think of the problem this way:&lt;br /&gt;
&lt;br /&gt;
Does a site need to load more than one script, at least one of which comes from a remote domain location (like a CDN), and for which among the scripts there&#039;s at least one execution-order dependency among them? If so, then that site is susceptible to the current/future breakage if the HTML spec (and browsers) do not address this use case.&lt;br /&gt;
&lt;br /&gt;
A common example (in use on many sites) of such might be loading:&lt;br /&gt;
&lt;br /&gt;
* jQuery from the CDN&lt;br /&gt;
* jQuery-UI from the CDN&lt;br /&gt;
* plugins and usage code in one or more local files&lt;br /&gt;
* Google Analytics from the Google domain&lt;br /&gt;
&lt;br /&gt;
Note that the emergence of popular script frameworks and their hosting on public CDN&#039;s is leading to more and more sites loading scripts from both local and remote locations, and also to loading more files that have dependencies (rather than the practice of concat&#039;ing all files into one file to avoid dependency issues).&lt;br /&gt;
&lt;br /&gt;
Any site which fits a profile like the above, and which might currently (many do), or in the future want to, use a script loader to improve their loading performance, will fail to achieve what they want cross-browser and in a performant way, if the HTML spec (and browsers) do not address the use case.&lt;br /&gt;
&lt;br /&gt;
=== Benefits ===&lt;br /&gt;
The benefits of addressing both behaviors directly (without &amp;quot;preloading&amp;quot; tricks and bad assumption reliance) have been implied in the above discussion, but in short are:&lt;br /&gt;
&lt;br /&gt;
a) clear and simplified code for script loaders, which leads to easier use by authors of more pages, which in turn leads to better web performance (as demonstrated clearly by intelligent script loading techniques as compared to just simple &amp;amp;lt;script&amp;gt; tags in HTML markup)&lt;br /&gt;
&lt;br /&gt;
b) full access to either/both of the execution-order behaviors (as the author sees fit), regardless of browser&lt;br /&gt;
&lt;br /&gt;
c) avoiding reliance on bad assumptions (like cacheability) as a sufficient way to address the use-case&lt;br /&gt;
&lt;br /&gt;
=== External Discussions of this Feature ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html W3C public-html email thread]&amp;lt;/cite&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://www.w3.org/Bugs/Public/show_bug.cgi?id=11295 W3C Bug #11295]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[https://bugzilla.mozilla.org/show_bug.cgi?id=602838 Mozilla Bug #602838]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[https://bugs.webkit.org/show_bug.cgi?id=50115 Webkit Bug #50115]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://hsivonen.iki.fi/script-execution/ HTML5 Script Execution Changes in Firefox 4 Beta 7]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://blog.getify.com/2010/10/labjs-w3c-brief-update/ LABjs and W3C... brief update]&amp;lt;/cite&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://blog.getify.com/2010/10/ff4-script-loaders-and-order-preservation/ FF4, script loaders, and order preservation]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proposed Solutions ==&lt;br /&gt;
&lt;br /&gt;
=== My Solution ===&lt;br /&gt;
The current proposal most well supported from the email discussion thread, and the one which I feel makes most sense, is described here.&lt;br /&gt;
&lt;br /&gt;
The HTML spec already defines the &amp;quot;async&amp;quot; attribute for parser-inserted script tags, which when set to &amp;quot;true&amp;quot;, changes their execution order behavior to be like script-inserted script-elements (in IE/Webkit), which is that they load in parallel and execute &amp;quot;as fast as possible&amp;quot; (ostensibly because the author is expressing no dependencies between multiple such &amp;quot;async&amp;quot;-marked scripts). Parser-inserted script elements without &amp;quot;async&amp;quot; (or with it set to false) behave as before and expected, which is that they load in parallel but execute in order.&lt;br /&gt;
&lt;br /&gt;
However, the HTML spec does not define the &amp;quot;async&amp;quot; property (or any such behavior) for script-inserted script nodes (such as those created by a script loader). Instead, the spec implies that &amp;quot;async=true&amp;quot; like behavior is always true for such script-inserted script elements.&lt;br /&gt;
&lt;br /&gt;
What is proposed is:&lt;br /&gt;
&lt;br /&gt;
a) Script-inserted script elements should have (and respect the value of) an &amp;quot;async&amp;quot; property which is basically identical to the &amp;quot;async&amp;quot; attribute for parser-inserted script elements. That is, script elements with the &amp;quot;async&amp;quot; property set to &amp;quot;true&amp;quot; will behave accordingly, as will script elements with the &amp;quot;async&amp;quot; property set to false. &lt;br /&gt;
&lt;br /&gt;
Essentially, the proposal is to mirror the &amp;quot;async&amp;quot; attribute behavior of parser-inserted script elements as an &amp;quot;async&amp;quot; property on script-inserted script elements. This has the benefit of using an existing facility and extending it (from current spec) in a way that is sensisble and symmetric with its current definition.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EFEFEF&amp;quot;&amp;gt;&lt;br /&gt;
The scriptgroup or `readyState`  alternate proposals allow for dependency management to be done in high-level code.  The singular syncrhonized execution queue proposed here introduces artificial dependencies, undermining some of the benefits dynamic script loading provides.  &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #ccc;&amp;quot;&amp;gt;&lt;br /&gt;
It&#039;s important to note that `async=false` scripts will load in a separate queue from `async=true` scripts. It&#039;s not that all scripts will now be forced into this insertion-order-execution queue. An author (or script loader) can chose which queue to put a script loading into based on the needs of the page and the resource. If I have a few scripts that are unrelated to each other and the main page (like Google Analytics, social sharing buttons, etc), I&#039;ll load those via `async=true`. For other scripts, where order matters for dependency sake, I&#039;ll use `async=false`. I think having both those queues available to high-level code is enough control over loading to serve the majority of use-cases pretty well.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EFEFEF&amp;quot;&amp;gt;&lt;br /&gt;
If at any point these services begin dynamically loading `async=false` scripts of their own, they will begin blocking.  This can lead to unexpected behavior of existing code as third-party libraries and services change.  It would seem the specification should provide a means by which this blocking can be isolated to dependencies defined by the author and ordered execution not introduce conditions that allow unrelated libraries to affect this.   &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b) Furthermore, to aid in &amp;quot;feature-detection&amp;quot; of such new behavior, the proposal is to have the default value for the &amp;quot;async&amp;quot; property of script-inserted script elements be &amp;quot;true&amp;quot; (and of course the associated behavior thereof).&lt;br /&gt;
&lt;br /&gt;
There are two major benefits to (b). One is that it provides a way to feature test such new behavior by not just looking for the existence of the &amp;quot;async&amp;quot; property on script elements, but specifically that the default value is &amp;quot;true&amp;quot; (which is opposite of what it would currently/normally be). Secondly, defaulting to &amp;quot;async=true&amp;quot; behavior for script-inserted script elements would preserve the default behavior of IE and Webkit, meaning there&#039;d be less of a chance of breaking existing web content in either of those two browsers.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also important to note that there is no implied or requested effect or dependency between script-inserted script elements and parser-inserted script elements -- the two types of scripts would load and execute in entirely separate behavioral sandboxes.&lt;br /&gt;
&lt;br /&gt;
==== Proposal Amendment: Events ====&lt;br /&gt;
In addition to standardizing how scripts load and execute, it&#039;s also important to standardize the load and error events, and under what circumstances they fire, etc. Without reliable load/error events, the main proposal is not reliable and is thus unhelpful for the use-case.&lt;br /&gt;
&lt;br /&gt;
A script-inserted script element must fire the &amp;quot;load&amp;quot; event only once, when:&lt;br /&gt;
&lt;br /&gt;
a) immediately after the resource finishes loading, but before parsing/execution, AND&lt;br /&gt;
&lt;br /&gt;
b) the script element loads any non-empty content (that is, it was a successful HTTP request), AND&lt;br /&gt;
&lt;br /&gt;
c) the script element has either loaded from the remote location, or is loaded from the brower cache&lt;br /&gt;
&lt;br /&gt;
Specifically, the script &amp;quot;load&amp;quot; event must come immediately between the script element finishing loading and the script element being parsed/executed. If the script resource successfully loads, nothing should interrupt the sequence of fininshing loading, the &amp;quot;load&amp;quot; event firing, and the script being parsed/executed.&lt;br /&gt;
&lt;br /&gt;
A script-inserted script element must fire the &amp;quot;error&amp;quot; event only once, when:&lt;br /&gt;
&lt;br /&gt;
a) immediately after a loading failure for the resource is detected (that is, an HTTP error received, such as 404, 500, 503, etc).&lt;br /&gt;
&lt;br /&gt;
Either the &amp;quot;load&amp;quot; or &amp;quot;error&amp;quot; event, but not both, will fire, and only once, for every script-inserted script element.&lt;br /&gt;
&lt;br /&gt;
NOTE: &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events on script-inserted script elements must fire synchronously to ensure event reliability.&lt;br /&gt;
&lt;br /&gt;
A case may be made for adding the &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events as described here to parser-inserted script elements as well.&lt;br /&gt;
&lt;br /&gt;
==== Processing Model ====&lt;br /&gt;
Script inserted script elements will have an &amp;quot;async&amp;quot; property that defaults to &amp;quot;true&amp;quot;. If the author does not change the value, all such requested script loadings will be in their own &amp;quot;queue&amp;quot; and will default to &amp;quot;as fast as possible&amp;quot; execution behavior. For any script elements that the author sets &amp;quot;async=false&amp;quot;, those scripts will load in a separate &amp;quot;queue&amp;quot;, and will execute in insertion order only. Again, these two &amp;quot;queues&amp;quot; will operate strictly independent of each other.&lt;br /&gt;
&lt;br /&gt;
==== Processing Model Details (without the event amendment) ====&lt;br /&gt;
&lt;br /&gt;
When a script element node is created, if it is being flagged as parser-inserted, set its force-async flag to false. Otherwise, set its force-async flag to true. (Note that createContextualFragment, innerHTML and XSLTProcessor::transformToFragment-created scripts are not flagged as parser-inserted.) This flag setting happens before any attributes (even parser-set ones) are set on the node.&lt;br /&gt;
&lt;br /&gt;
When a previously-created script element node loses its parser-insertedness, if the element doesn&#039;t have the async content attribute, set the force-async flag to true and false otherwise.&lt;br /&gt;
&lt;br /&gt;
When a script element node obtains the async content attribute (via setAttribute, setAttributeNode, setAttributeNS, by the fragment parser or the XSLTProcessor adding the attribute, etc.), set the force-async flag to false. (Note that calling removeAttribute(&amp;quot;async&amp;quot;) doesn&#039;t modify the force-async flag.)&lt;br /&gt;
&lt;br /&gt;
The async IDL attribute must behave as follows:&lt;br /&gt;
* Upon setting, set the force-async flag to false and then reflect the async content attribute.&lt;br /&gt;
* Upon getting, if the force-async flag is true, return true. Otherwise, reflect the async content attribute.&lt;br /&gt;
&lt;br /&gt;
In step 13. of http://www.whatwg.org/specs/web-apps/current-work/#running-a-script before the case &amp;quot;If the element has a src attribute&amp;quot; add a case:&lt;br /&gt;
If the script has a src attribute and the async IDL property getter returns false,&lt;br /&gt;
The element must be added to the queue of ordered script-inserted external scripts of the Document of the script element at the time the running a script algorithm started.&lt;br /&gt;
&lt;br /&gt;
The task that the networking task source places on the task queue once the fetching algorithm has completed must run these steps:&lt;br /&gt;
# If the queue of ordered script-inserted external scripts is empty or the first script in the queue of ordered script-inserted external scripts has not been fetched yet, abort these steps.&lt;br /&gt;
# Execute the first script in the queue of ordered script-inserted external scripts.&lt;br /&gt;
# Remove the first script from queue of ordered script-inserted external scripts.&lt;br /&gt;
# Goto step #1.&lt;br /&gt;
&lt;br /&gt;
Modify step 5 of  http://www.whatwg.org/specs/web-apps/current-work/#the-end to say:&lt;br /&gt;
Spin the event loop until the set of scripts that will execute as soon as possible is empty and the queue of ordered script-inserted external scripts is empty.&lt;br /&gt;
&lt;br /&gt;
==== Limitations ==== &lt;br /&gt;
The two behaviors being identified solve either the case where no dependencies exist, or where a linear dependency chain exists (and which the script elements can be requested to execute in that order). It is possible that some authors have a more complex non-linear dependency chain that they would like to express. This would obviously require a much more complex API and spec change, and since that use-case has not (yet) surfaced as a particularly main-stream request, I believe it would be overengineering to try to address it with this proposed change set.&lt;br /&gt;
&lt;br /&gt;
In addition, it&#039;s been duly noted that it&#039;s undesirable (and potentially confusing/problematic) to intentionally build in the inconsistency of having the &amp;quot;async&amp;quot; attribute (for parser-inserted scripts) and the &amp;quot;async&amp;quot; property (for script-inserted scripts) have different default values (&amp;quot;false&amp;quot; for the attribute, &amp;quot;true&amp;quot; for the property).&lt;br /&gt;
&lt;br /&gt;
It&#039;s also been a point of discussion whether or not such a spec change has enough &amp;quot;carrot&amp;quot; to entice the browser vendors (namely IE and Webkit) to implement the behavior. Moreover, there&#039;s been some concern that if the default value for the &amp;quot;async&amp;quot; property were made to be &amp;quot;false&amp;quot; (like the attribute) to be more consistent and conservative, then it would possibly give the perception to IE and Webkit of &amp;quot;losing&amp;quot; some performance to cut out their default &amp;quot;as fast as possible&amp;quot; behavior.&lt;br /&gt;
&lt;br /&gt;
=== Alternate Proposals === &lt;br /&gt;
One early proposal on the email list was to introduce an entirely new property like &amp;quot;ordered&amp;quot; which an author could add to a script-inserted script element to instruct the browser to put it into the queue of execution-order-preserving script loadings. While such a property would address the use case, it introduces another property and thus more complicates the issue. It also fails to address the current spec inconsistency (which is confusing to new comers) that &amp;quot;async&amp;quot; is not a present/respected property in mirror of the attribute of the same name.&lt;br /&gt;
&lt;br /&gt;
Another suggestion was a &amp;quot;waitFor&amp;quot; property that would be added to script elements and would specify a list of one or more DOM id&#039;s of other script elements that the current script should &amp;quot;wait for&amp;quot; in terms of execution. Again, this would solve the use case, but in a more complicated way, and there are concerns that it would be too confusing for the normal use-case.&lt;br /&gt;
&lt;br /&gt;
Several suggestions have come in the form of creating explicit &amp;quot;preloading&amp;quot; (similar to &amp;amp;lt;link rel=prefetch&amp;gt;), but as described above, &amp;quot;preloading&amp;quot; to solve this use case is a non-ideal hack and highly susceptible to breakage if the script fails to be sent with proper caching headers.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also been suggested that since this type of behavior is somewhat complicated, it may be better to intentionally obfuscate or complicate any such facility in the HTML, so as to make the barrier-to-entry rather high and force users to know what they are doing before doing it.&lt;br /&gt;
&lt;br /&gt;
It&#039;s been suggested that &amp;quot;defer&amp;quot; already preserves execution order. However, &amp;quot;defer&amp;quot; is only defined for parser-inserted scripts, and thus is not applicable to the use-case in question from an on-demand point of view. Also, &amp;quot;defer&amp;quot; scripts explicitly way for DOMContentLoaded, even if they&#039;re ready to execute sooner. So this is less than desired.&lt;br /&gt;
&lt;br /&gt;
Yet another proposal is a &amp;quot;document.executeScripts()&amp;quot; API, where an author can specify multiple sets of scripts that can load in parallel and it will enforce their execution order. A variation on that same idea was to use the &amp;quot;importScripts&amp;quot; from the Web Workers spec, however &amp;quot;importScripts&amp;quot; is synchronous (undesirable performance wise, obviously). The main downside (besides extra API complication) to &amp;quot;document.executeScripts()&amp;quot; is that there seem to be quite a few script execution properties/behaviors (including &amp;quot;document.currentScript&amp;quot; and charset override) which would have to be duplicated into this API facility.&lt;br /&gt;
&lt;br /&gt;
==== &amp;quot;Script Group&amp;quot; element ====&lt;br /&gt;
One recent alternate proposal bears some special consideration, as it seems like it might be a decent option (although certainly more of a radical change for the spec and for browsers to implement). But it has the appearance of being pretty straightforward and semantic for authors to use, perhaps even more so than using &amp;quot;async&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The proposal is to create a new HTML element, called perhaps &amp;amp;lt;scriptGroup&amp;gt;, &amp;amp;lt;collection&amp;gt;, etc. Specifically, this element must be able to be inserted wherever a &amp;amp;lt;script&amp;gt; element can currently be inserted. The &amp;quot;script group&amp;quot; element is intended to signify that all script elements added to it must perserve insertion execution order. This element wouldn&#039;t have much (but still some, explained in a moment) meaning in a parser-inserted context, since parser-inserted scripts already preserve order among themselves.&lt;br /&gt;
&lt;br /&gt;
An advantage of the &amp;quot;script group&amp;quot; element would be to give a direct and easy way to attach event listeners (&amp;quot;load&amp;quot; and &amp;quot;error&amp;quot;) to the entire group, rather than having to internally track events for each element if all you care about is the final &amp;quot;load&amp;quot; event, for instance. In the case of event handling, the &amp;quot;script group&amp;quot; element would have perhaps some benefit even in parser-inserted (markup) context.&lt;br /&gt;
&lt;br /&gt;
The element would need to have an &amp;quot;id&amp;quot; property, and possibly attributes for &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events.&lt;br /&gt;
&lt;br /&gt;
A variation on how to look at this proposal is that a &amp;quot;script group&amp;quot; element could have an attribute/property on it (perhaps called &amp;quot;ordered&amp;quot;) which would allow the group to either be order preserved or not. This would make the &amp;quot;script group&amp;quot; element much more useful in the parser-inserted context, as it would sort of be a shortcut to setting &amp;quot;async=true&amp;quot; on all the child script elements.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;script group&amp;quot; element might look like this:&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group1&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;foo.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;bar.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      somethingInline();&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, with the &amp;quot;ordered&amp;quot; attribute to explicitly control ordering behavior for the group:&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group1&amp;quot; ordered=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;foo.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;bar.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      somethingInline();&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group2&amp;quot; ordered=&amp;quot;false&amp;quot; onload=&amp;quot;alldone();&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;baz.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;far.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;zab.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the &amp;quot;script group&amp;quot; element is definitely more complicated to define and implement, it does have some semantic advantages for authors, and it also would significantly reduce the internal complexity of script loaders like LABjs. It would give authors (either directly or through script loaders) the flexibility to group scripts together into one of the two aforementioned behaviors (execution &amp;quot;as fast as possible&amp;quot; or &amp;quot;in insertion order&amp;quot;), and to easily access both behaviors in the same page.&lt;br /&gt;
&lt;br /&gt;
==== Explicit support for &amp;quot;text/cache&amp;quot; MIME type behavior ====&lt;br /&gt;
Yet another alternate proposal has been suggested in the [[Talk:Dynamic_Script_Execution_Order]] thread. &lt;br /&gt;
&lt;br /&gt;
Essentially, the proposal is that &amp;amp;lt;script&amp;gt; tags directly support being declared with a `type` value of &amp;quot;text/cache&amp;quot;. The behavior would be that the script resource is fetched, as the load events fired, as normal, but that the script itself would not be executed. Then later, at the desired time, the script in that element could be executed by changing the `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The browser would probably need to keep track (via some internal flag) that the script node is only ever executed once. Also, it&#039;s an open question if such a &amp;quot;cached&amp;quot; script node should be able to have its script content modified before execution via the `text` property.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
And does the onload event fire again after the script executes?  &amp;lt;br/&amp;gt; &lt;br /&gt;
Or only when it&#039;s loaded? &amp;lt;br/&amp;gt; &lt;br /&gt;
Both seem to violate current `onload` semantics.  &lt;br /&gt;
[[User:Serverherder|Serverherder]] 20:27, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== readyState &amp;quot;preloading&amp;quot; ====&lt;br /&gt;
Per the suggestion/comment added to the above [[Dynamic_Script_Execution_Order#Current_Limitations|Current Limitations]] section, it&#039;s been suggested that IE&#039;s current behavior with respect to the `readyState` property can adequately serve the use-case in question. This alternate proposal is very similar in spirit to the [[Dynamic_Script_Execution_Order#Explicit_support_for_.22text.2Fcache.22_MIME_type_behavior|previous section on explicit support for &amp;quot;text/cache&amp;quot;]] mime-type value.&lt;br /&gt;
&lt;br /&gt;
The idea is that IE will begin fetching into the cache a script resource as soon as the `src` attribute of the dynamic script element is set. But IE will not execute the script (even if it finishes loading) until the script element is added to the DOM. However, the `readyState` property of the element, combined with the `onreadystatechange` handler listening for changes, can detect when the script has finished loading, by receiving the &amp;quot;loaded&amp;quot; value.&lt;br /&gt;
&lt;br /&gt;
In this way, a script loader could &amp;quot;preload&amp;quot; a set of scripts all in parallel, but control their execution order by delaying the appending of the element to the DOM until execution is desired.&lt;br /&gt;
&lt;br /&gt;
[[Category:Feature Request|Dynamic Script Execution Order]]&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5626</id>
		<title>Talk:Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5626"/>
		<updated>2010-12-15T19:51:08Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* RequireJS order support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please discuss the proposal here. All informal feedback is welcomed, and when it&#039;s appropriate, please add content to the main page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What about CommonJS / RequireJS? ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m not sure we need to complicate the HTML or browser engines in order to satisfy the advanced use cases.  To me it seems that the JavaScript langauge itself could abstract the requirements and let the browser vendors implement whatever solution they see fit.  Specifically, if JavaScript provided the define() and require() calls proposed in the CommonJS &amp;quot;specifications&amp;quot; (and implemented by [http://requirejs.org/docs/api.html RequireJS], [http://svn.dojotoolkit.org/src/dojo/trunk/_base/_loader/loader.js dojo (trunk)], and others *Yabble?), then browsers could just load and evaluate scripts as fast as possible without regard to script execution order.  &lt;br /&gt;
&lt;br /&gt;
This would solve all of the problems except for the current inability to use loaders like LABjs in FF4 or webkit.  To solve that problem, we should consider keeping the existing functionality or triggering the deprecated functionality when needed.&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
=== Response ===&lt;br /&gt;
&lt;br /&gt;
This is a valid point except that it assumes that all code that needs to be loaded is &amp;quot;modular&amp;quot;... in fact, most code on the internet that needs to be loaded is NOT modular, and instead requires particular ordering when being loaded... for instance, &amp;quot;jquery&amp;quot; and &amp;quot;jquery-ui&amp;quot; -- jQuery must be run before jQuery-UI is loaded and run.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The spirit of this proposal is to add the facility to native browser (rendering engine, specifically) behavior, such that any and all existing content is able to be loaded (even with dependencies and order) without modification.&lt;br /&gt;
&amp;lt;blockquote style=background-color:#eee&amp;gt;&lt;br /&gt;
Are we trying to codify how one would implement this HTML dynamically so I can achieve parallel loading but retain dependency that is inferred in the order? &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: white&amp;quot;&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery-ui.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If so, we must consider the case in which the dependency itself loads additional code which the discussions around `async=false` or even text/cache do not account for.  &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:23, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dependent code should be modular ===&lt;br /&gt;
&lt;br /&gt;
I completely agree, 99% of JavaScript in use today is NOT modular, but that&#039;s arguably because there was no built-in support to make it modular (IMHO, YMMV, RTFM, BBQ, ROFL).  But that doesn&#039;t mean there aren&#039;t dependencies that span script files / script nodes.  I don&#039;t know how many sites would be broken (or if there is any way to determine how many sites would be broken) if/when the latest browsers started loading and evaluating script-injected scripts out of order.  It&#039;s not just LABjs-based sites.  I&#039;ll bet many dojo and YUI sites will break, too (although I don&#039;t know this for a fact because I don&#039;t know exactly how their dynamic script loaders work).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;In any case, breaking existing sites is a BAD IDEA. :)  There should be some way to allow LABjs and other dynamic script loaders to continue to work.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The part I don&#039;t agree with in the proposals is that it should be the job of HTML and/or the browser engine to manage dependencies.  Specifically, I am talking about the scriptGroup element and the &amp;quot;waitFor&amp;quot; attribute.  The &amp;quot;async&amp;quot; attribute may be the right level: it appropriates only general heuristics to the browser: &#039;&#039;load these scripts whenever you like, but load these other scripts in this order&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Detailed dependency management belongs in the modules, though.  This is how it&#039;s done in most environments / languages: import statements, include statements, etc.  It&#039;s no different in JavaScript, if a developer wants to take advantage of some code in another module, she/he should import it into their current module.  This should be the model moving forward.  It&#039;s not hard, it&#039;s not un-web-like, and it&#039;s already being done.  &lt;br /&gt;
&lt;br /&gt;
Existing code can be made to work modularly, too:&lt;br /&gt;
&lt;br /&gt;
1. Identify modules and wrap them with a define() method.&lt;br /&gt;
2. Identify dependencies using either the [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition Asynchronous Module Definition] format or the CommonJS synchronous format&lt;br /&gt;
&lt;br /&gt;
async format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define([&#039;dependency1&#039;, &#039;dependency2&#039;], function (dependency1, dependency2) {&lt;br /&gt;
	/* this is the factory function, return the module inside here */&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sync format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define(function (require, exports, module) {&lt;br /&gt;
	/* this is the factory function, require dependencies and return the module inside here */&lt;br /&gt;
	var dependency1 = require(&#039;dependency1&#039;);&lt;br /&gt;
	var dependency2 = require(&#039;dependency2&#039;);&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the async case, the browser may employ whatever method it sees fit (e.g. parallel) to download the dependencies since the code inside the factory function won&#039;t execute until all of the dependencies are loaded and evaluated.  In the sync case, the browser has no choice but to download and evaluate the dependency before continuing code execution.  It&#039;s conceivable that the browser could find and asynchronously pre-fetch the inline require()&#039;ed dependencies in the sync case.  (RequireJS doesn&#039;t quite do this.  Instead I believe it finds the inline require() calls and converts the module to an async module.)  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;So, in short: don&#039;t break LABjs (or any other script loaders), but don&#039;t extend the spec to manage dependency management from HTML.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Response #2 ==&lt;br /&gt;
&lt;br /&gt;
The cat&#039;s already out of the bag... we&#039;ve got a dozen+ years worth, hundreds of millions of javascript files out there, which are NOT modular, and will not be modified to be modular. &lt;br /&gt;
&lt;br /&gt;
If we&#039;re talking about either trying to change all the JS on the web to be modular, or trying to extend the HTML markup spec to include a better facility for accomodating the existing script content, I think the former is idealistic and &amp;quot;correct&amp;quot; but the latter is realistic and &amp;quot;right&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
A modular loading system will only work for modular code, but a general loading mechanism in HTML (like the &amp;amp;lt;script&amp;gt; tag) can load both modular and non-modular code, which is why that more general mechanism is what&#039;s in HTML right now and not some more specialized loading API that only loads a small percentage of JavaScript code out there.&lt;br /&gt;
&lt;br /&gt;
The &amp;amp;lt;script&amp;gt; tag has worked fine forever, and there&#039;s been no real big push to do away with it in favor of having all loading handled by JavaScript -- in fact, that would be impossible because if you had no way to load JS onto the page with a &amp;amp;lt;script&amp;gt; tag, then no JavaScript could run on a page to load more code. So I don&#039;t agree that we should stop adding functionality to the HTML loading mechanism and only focus on JavaScript.&lt;br /&gt;
&lt;br /&gt;
If we agree that the &amp;amp;lt;script&amp;gt; tag itself is not only required but normative, then I&#039;m not sure why decorating the &amp;amp;lt;script&amp;gt; tag with additional behavior to help it be more powerful is a bad pattern. We&#039;ve addded &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; already. I&#039;m not sure I understand why adding a wrapper tag called &amp;quot;scriptGroup&amp;quot; would be that much different than attributes on the &amp;amp;lt;script&amp;gt; tag?&lt;br /&gt;
&lt;br /&gt;
I also don&#039;t think that &amp;quot;scriptGroup&amp;quot; constitutes &amp;quot;dependency management&amp;quot;. &amp;quot;scriptGroup&amp;quot; is a semantic way for a web author to express that they want to group a set of scripts together ONLY so far as execution order behavior is concerned. It implies nothing more to it (that &amp;quot;dependency management&amp;quot; would imply) than that.&lt;br /&gt;
&lt;br /&gt;
For instance, consider this: if JavaScript had been built with non-global context and statement level context and sandboxing and such things, we&#039;d have a much more secure JavaScript right now. But just because JavaScript may someday be taught some new tricks in terms of security, that doesn&#039;t mean that &amp;quot;now&amp;quot; HTML shouldn&#039;t try to help solve the problem. If for instance the &amp;amp;lt;frag&amp;gt; tag can be used to create a sandboxed environment for third-party JavaScript code to run in, this is a much easier way to address the security problem than to suggest we have to wait for ES-Harmony to add extra syntax to the language to accomplish the same thing.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 02:13, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Text/cache solution ==&lt;br /&gt;
&lt;br /&gt;
It seems to me that having a real text/cache script type, or a similar element that fires a load/error event and provides a .text property gets you where you need to be. You could setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/JavaScript&amp;quot;) or use the text to create a new script element. Or a new style element, or whatever. That puts you in control of when script or CSS is interpreted. With async as the default, you don&#039;t need a new ordered attribute as that&#039;s easily managed in script.&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;text/cache&amp;quot; response ==&lt;br /&gt;
&lt;br /&gt;
On the surface, this idea sounds like it&#039;s pretty similar to &amp;amp;lt;link rel=prefetch&amp;gt; -- in other words, we&#039;ve already standardized a way to prefetch a resource into cache, and probably in a better way than the hack that I did in LABjs of just relying on it fetching unrecognizable content.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it still suffers some similar problems to &amp;amp;lt;link rel=prefetch&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Firstly, if the notion is that you&#039;d use &amp;amp;lt;script type=&amp;quot;text/cache&amp;quot;&amp;gt; to prefetch, and then you&#039;d make a second request for the resource with a real &amp;amp;lt;script type=&amp;quot;text/javascript&amp;gt; node, it suffers the faulty assumption that the resource was served with proper cache headers.&lt;br /&gt;
&lt;br /&gt;
If we try to avoid the need for the second request by suggesting that you can access the `text` property of the node (and then eval() or inject that code when you want to execute it), this runs afoul of the same-origin policy problem if you requested the script from a non-local domain.&lt;br /&gt;
&lt;br /&gt;
The part of your suggestion that holds water would be if, given a &amp;quot;prefetched&amp;quot; script node that didn&#039;t execute yet, I could simply change that node&#039;s `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;, and that would explicitly trigger the browser to immediately execute it. &lt;br /&gt;
&lt;br /&gt;
This is an interesting idea. I can see though that it perhaps has some potential complications. &lt;br /&gt;
&lt;br /&gt;
For instance, would the browser have to keep a &amp;quot;hasExecuted&amp;quot; internal flag, so that changing the `type` value would only at most result in one execution? Also, if the script node in question is loaded but not executed, can the page alter the script code (by setting its `text` property) before making the change to the `type` value? In that case, should the browser execute the original code or the modified code? I can see security implications and confusion abounding in that behavior.&lt;br /&gt;
&lt;br /&gt;
Lastly, as mentioned above, this basically copies (in a similar but not exactly identical way) the &amp;amp;lt;link rel=prefetch&amp;gt; behavior. It may be seen as a negative to be trying to step on the toes of &amp;amp;lt;link rel=prefetch&amp;gt;, and also it may be more confusing to the general public as to why you&#039;d use one technique or the other, given their differences being so nuanced.&lt;br /&gt;
&lt;br /&gt;
That having been said, I can see that it&#039;s a viable alternate proposal. It&#039;s worth adding a note to that section of the main Wiki page and to getting some feedback from browser vendors on if they feel this is a more realistic/suitable solution to the use-case.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #eee&amp;quot;&amp;gt;&lt;br /&gt;
The difference between pre-fetching and this proposal seems pretty clear: Prefetching, if not performed now, will eventually be done once the user explicitly requests the page. while the &amp;quot;text/cache&amp;quot; solution indicates that the resource should load &#039;&#039;&#039;immediately&#039;&#039;&#039;, not during idle time. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:10, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 20:56, 4 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== RequireJS order support ==&lt;br /&gt;
&lt;br /&gt;
I am the main developer for RequireJS, and just want to voice my support for a solution that works on the script element itself, either by leveraging the async attribute or allowing something like an &amp;quot;order&amp;quot; boolean attribute that would allow specifying a dynamically added script element should be executed in the order that it appears in the DOM. This capability should be something can be capability detected to avoid browser sniffing.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Why shouldn&#039;t dependency management be implemented in high-level code and the browser simply provide a means by which parallel loading can be achieved?  As you know, there is a considerable amount of nuance.  I&#039;m of the opinion that implementing dependency management in the engine will eventually lead us right back to where we were 10 years ago with inline script tags which provides an easy method for dependency management at the expense of unmanaged blocking and an inability to detect or adapt to errors. &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
There are many scripts on the web today that have implicit dependencies that should be loaded in a specific order, but the application developer will want to use dynamically created script elements for best performance. jQuery plugins that depend on the jQuery script already been executed in the page are a good example.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Agreed, but I don&#039;t believe the proposals allow for proper emulation of the dependency management provided by script tags.  Prototype.js, for example, loads its core modules dynamically (using document.write so maybe not the best example...).  When prototype.js is included via script tags, ensuing script blocks are free to &amp;quot;depend&amp;quot; on all of these modules; Dynamically creating a dependency on prototype.js by loading both with the `async=true` property will fail since prototype.js won&#039;t be able to &amp;quot;jump the queue&amp;quot; and add insure its core modules load before its extensions.  &amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:51, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
- James Burke&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5625</id>
		<title>Talk:Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5625"/>
		<updated>2010-12-15T19:44:57Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* RequireJS order support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please discuss the proposal here. All informal feedback is welcomed, and when it&#039;s appropriate, please add content to the main page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What about CommonJS / RequireJS? ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m not sure we need to complicate the HTML or browser engines in order to satisfy the advanced use cases.  To me it seems that the JavaScript langauge itself could abstract the requirements and let the browser vendors implement whatever solution they see fit.  Specifically, if JavaScript provided the define() and require() calls proposed in the CommonJS &amp;quot;specifications&amp;quot; (and implemented by [http://requirejs.org/docs/api.html RequireJS], [http://svn.dojotoolkit.org/src/dojo/trunk/_base/_loader/loader.js dojo (trunk)], and others *Yabble?), then browsers could just load and evaluate scripts as fast as possible without regard to script execution order.  &lt;br /&gt;
&lt;br /&gt;
This would solve all of the problems except for the current inability to use loaders like LABjs in FF4 or webkit.  To solve that problem, we should consider keeping the existing functionality or triggering the deprecated functionality when needed.&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
=== Response ===&lt;br /&gt;
&lt;br /&gt;
This is a valid point except that it assumes that all code that needs to be loaded is &amp;quot;modular&amp;quot;... in fact, most code on the internet that needs to be loaded is NOT modular, and instead requires particular ordering when being loaded... for instance, &amp;quot;jquery&amp;quot; and &amp;quot;jquery-ui&amp;quot; -- jQuery must be run before jQuery-UI is loaded and run.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The spirit of this proposal is to add the facility to native browser (rendering engine, specifically) behavior, such that any and all existing content is able to be loaded (even with dependencies and order) without modification.&lt;br /&gt;
&amp;lt;blockquote style=background-color:#eee&amp;gt;&lt;br /&gt;
Are we trying to codify how one would implement this HTML dynamically so I can achieve parallel loading but retain dependency that is inferred in the order? &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: white&amp;quot;&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery-ui.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If so, we must consider the case in which the dependency itself loads additional code which the discussions around `async=false` or even text/cache do not account for.  &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:23, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dependent code should be modular ===&lt;br /&gt;
&lt;br /&gt;
I completely agree, 99% of JavaScript in use today is NOT modular, but that&#039;s arguably because there was no built-in support to make it modular (IMHO, YMMV, RTFM, BBQ, ROFL).  But that doesn&#039;t mean there aren&#039;t dependencies that span script files / script nodes.  I don&#039;t know how many sites would be broken (or if there is any way to determine how many sites would be broken) if/when the latest browsers started loading and evaluating script-injected scripts out of order.  It&#039;s not just LABjs-based sites.  I&#039;ll bet many dojo and YUI sites will break, too (although I don&#039;t know this for a fact because I don&#039;t know exactly how their dynamic script loaders work).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;In any case, breaking existing sites is a BAD IDEA. :)  There should be some way to allow LABjs and other dynamic script loaders to continue to work.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The part I don&#039;t agree with in the proposals is that it should be the job of HTML and/or the browser engine to manage dependencies.  Specifically, I am talking about the scriptGroup element and the &amp;quot;waitFor&amp;quot; attribute.  The &amp;quot;async&amp;quot; attribute may be the right level: it appropriates only general heuristics to the browser: &#039;&#039;load these scripts whenever you like, but load these other scripts in this order&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Detailed dependency management belongs in the modules, though.  This is how it&#039;s done in most environments / languages: import statements, include statements, etc.  It&#039;s no different in JavaScript, if a developer wants to take advantage of some code in another module, she/he should import it into their current module.  This should be the model moving forward.  It&#039;s not hard, it&#039;s not un-web-like, and it&#039;s already being done.  &lt;br /&gt;
&lt;br /&gt;
Existing code can be made to work modularly, too:&lt;br /&gt;
&lt;br /&gt;
1. Identify modules and wrap them with a define() method.&lt;br /&gt;
2. Identify dependencies using either the [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition Asynchronous Module Definition] format or the CommonJS synchronous format&lt;br /&gt;
&lt;br /&gt;
async format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define([&#039;dependency1&#039;, &#039;dependency2&#039;], function (dependency1, dependency2) {&lt;br /&gt;
	/* this is the factory function, return the module inside here */&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sync format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define(function (require, exports, module) {&lt;br /&gt;
	/* this is the factory function, require dependencies and return the module inside here */&lt;br /&gt;
	var dependency1 = require(&#039;dependency1&#039;);&lt;br /&gt;
	var dependency2 = require(&#039;dependency2&#039;);&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the async case, the browser may employ whatever method it sees fit (e.g. parallel) to download the dependencies since the code inside the factory function won&#039;t execute until all of the dependencies are loaded and evaluated.  In the sync case, the browser has no choice but to download and evaluate the dependency before continuing code execution.  It&#039;s conceivable that the browser could find and asynchronously pre-fetch the inline require()&#039;ed dependencies in the sync case.  (RequireJS doesn&#039;t quite do this.  Instead I believe it finds the inline require() calls and converts the module to an async module.)  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;So, in short: don&#039;t break LABjs (or any other script loaders), but don&#039;t extend the spec to manage dependency management from HTML.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Response #2 ==&lt;br /&gt;
&lt;br /&gt;
The cat&#039;s already out of the bag... we&#039;ve got a dozen+ years worth, hundreds of millions of javascript files out there, which are NOT modular, and will not be modified to be modular. &lt;br /&gt;
&lt;br /&gt;
If we&#039;re talking about either trying to change all the JS on the web to be modular, or trying to extend the HTML markup spec to include a better facility for accomodating the existing script content, I think the former is idealistic and &amp;quot;correct&amp;quot; but the latter is realistic and &amp;quot;right&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
A modular loading system will only work for modular code, but a general loading mechanism in HTML (like the &amp;amp;lt;script&amp;gt; tag) can load both modular and non-modular code, which is why that more general mechanism is what&#039;s in HTML right now and not some more specialized loading API that only loads a small percentage of JavaScript code out there.&lt;br /&gt;
&lt;br /&gt;
The &amp;amp;lt;script&amp;gt; tag has worked fine forever, and there&#039;s been no real big push to do away with it in favor of having all loading handled by JavaScript -- in fact, that would be impossible because if you had no way to load JS onto the page with a &amp;amp;lt;script&amp;gt; tag, then no JavaScript could run on a page to load more code. So I don&#039;t agree that we should stop adding functionality to the HTML loading mechanism and only focus on JavaScript.&lt;br /&gt;
&lt;br /&gt;
If we agree that the &amp;amp;lt;script&amp;gt; tag itself is not only required but normative, then I&#039;m not sure why decorating the &amp;amp;lt;script&amp;gt; tag with additional behavior to help it be more powerful is a bad pattern. We&#039;ve addded &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; already. I&#039;m not sure I understand why adding a wrapper tag called &amp;quot;scriptGroup&amp;quot; would be that much different than attributes on the &amp;amp;lt;script&amp;gt; tag?&lt;br /&gt;
&lt;br /&gt;
I also don&#039;t think that &amp;quot;scriptGroup&amp;quot; constitutes &amp;quot;dependency management&amp;quot;. &amp;quot;scriptGroup&amp;quot; is a semantic way for a web author to express that they want to group a set of scripts together ONLY so far as execution order behavior is concerned. It implies nothing more to it (that &amp;quot;dependency management&amp;quot; would imply) than that.&lt;br /&gt;
&lt;br /&gt;
For instance, consider this: if JavaScript had been built with non-global context and statement level context and sandboxing and such things, we&#039;d have a much more secure JavaScript right now. But just because JavaScript may someday be taught some new tricks in terms of security, that doesn&#039;t mean that &amp;quot;now&amp;quot; HTML shouldn&#039;t try to help solve the problem. If for instance the &amp;amp;lt;frag&amp;gt; tag can be used to create a sandboxed environment for third-party JavaScript code to run in, this is a much easier way to address the security problem than to suggest we have to wait for ES-Harmony to add extra syntax to the language to accomplish the same thing.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 02:13, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Text/cache solution ==&lt;br /&gt;
&lt;br /&gt;
It seems to me that having a real text/cache script type, or a similar element that fires a load/error event and provides a .text property gets you where you need to be. You could setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/JavaScript&amp;quot;) or use the text to create a new script element. Or a new style element, or whatever. That puts you in control of when script or CSS is interpreted. With async as the default, you don&#039;t need a new ordered attribute as that&#039;s easily managed in script.&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;text/cache&amp;quot; response ==&lt;br /&gt;
&lt;br /&gt;
On the surface, this idea sounds like it&#039;s pretty similar to &amp;amp;lt;link rel=prefetch&amp;gt; -- in other words, we&#039;ve already standardized a way to prefetch a resource into cache, and probably in a better way than the hack that I did in LABjs of just relying on it fetching unrecognizable content.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it still suffers some similar problems to &amp;amp;lt;link rel=prefetch&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Firstly, if the notion is that you&#039;d use &amp;amp;lt;script type=&amp;quot;text/cache&amp;quot;&amp;gt; to prefetch, and then you&#039;d make a second request for the resource with a real &amp;amp;lt;script type=&amp;quot;text/javascript&amp;gt; node, it suffers the faulty assumption that the resource was served with proper cache headers.&lt;br /&gt;
&lt;br /&gt;
If we try to avoid the need for the second request by suggesting that you can access the `text` property of the node (and then eval() or inject that code when you want to execute it), this runs afoul of the same-origin policy problem if you requested the script from a non-local domain.&lt;br /&gt;
&lt;br /&gt;
The part of your suggestion that holds water would be if, given a &amp;quot;prefetched&amp;quot; script node that didn&#039;t execute yet, I could simply change that node&#039;s `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;, and that would explicitly trigger the browser to immediately execute it. &lt;br /&gt;
&lt;br /&gt;
This is an interesting idea. I can see though that it perhaps has some potential complications. &lt;br /&gt;
&lt;br /&gt;
For instance, would the browser have to keep a &amp;quot;hasExecuted&amp;quot; internal flag, so that changing the `type` value would only at most result in one execution? Also, if the script node in question is loaded but not executed, can the page alter the script code (by setting its `text` property) before making the change to the `type` value? In that case, should the browser execute the original code or the modified code? I can see security implications and confusion abounding in that behavior.&lt;br /&gt;
&lt;br /&gt;
Lastly, as mentioned above, this basically copies (in a similar but not exactly identical way) the &amp;amp;lt;link rel=prefetch&amp;gt; behavior. It may be seen as a negative to be trying to step on the toes of &amp;amp;lt;link rel=prefetch&amp;gt;, and also it may be more confusing to the general public as to why you&#039;d use one technique or the other, given their differences being so nuanced.&lt;br /&gt;
&lt;br /&gt;
That having been said, I can see that it&#039;s a viable alternate proposal. It&#039;s worth adding a note to that section of the main Wiki page and to getting some feedback from browser vendors on if they feel this is a more realistic/suitable solution to the use-case.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #eee&amp;quot;&amp;gt;&lt;br /&gt;
The difference between pre-fetching and this proposal seems pretty clear: Prefetching, if not performed now, will eventually be done once the user explicitly requests the page. while the &amp;quot;text/cache&amp;quot; solution indicates that the resource should load &#039;&#039;&#039;immediately&#039;&#039;&#039;, not during idle time. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:10, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 20:56, 4 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== RequireJS order support ==&lt;br /&gt;
&lt;br /&gt;
I am the main developer for RequireJS, and just want to voice my support for a solution that works on the script element itself, either by leveraging the async attribute or allowing something like an &amp;quot;order&amp;quot; boolean attribute that would allow specifying a dynamically added script element should be executed in the order that it appears in the DOM. This capability should be something can be capability detected to avoid browser sniffing.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#eee&amp;quot;&amp;gt;&lt;br /&gt;
Why shouldn&#039;t dependency management be implemented in high-level code and the browser simply provide a means by which parallel loading can be achieved?  As you know, there is a considerable amount of nuance.  I&#039;m of the opinion that implementing dependency management in the engine will eventually lead us right back to where we were 10 years ago with inline script tags which provides an easy method for dependency management at the expense of unmanaged blocking and an inability to detect or adapt to errors. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
There are many scripts on the web today that have implicit dependencies that should be loaded in a specific order, but the application developer will want to use dynamically created script elements for best performance. jQuery plugins that depend on the jQuery script already been executed in the page are a good example.&lt;br /&gt;
&lt;br /&gt;
- James Burke&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5624</id>
		<title>Talk:Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5624"/>
		<updated>2010-12-15T19:30:56Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* Response */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please discuss the proposal here. All informal feedback is welcomed, and when it&#039;s appropriate, please add content to the main page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What about CommonJS / RequireJS? ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m not sure we need to complicate the HTML or browser engines in order to satisfy the advanced use cases.  To me it seems that the JavaScript langauge itself could abstract the requirements and let the browser vendors implement whatever solution they see fit.  Specifically, if JavaScript provided the define() and require() calls proposed in the CommonJS &amp;quot;specifications&amp;quot; (and implemented by [http://requirejs.org/docs/api.html RequireJS], [http://svn.dojotoolkit.org/src/dojo/trunk/_base/_loader/loader.js dojo (trunk)], and others *Yabble?), then browsers could just load and evaluate scripts as fast as possible without regard to script execution order.  &lt;br /&gt;
&lt;br /&gt;
This would solve all of the problems except for the current inability to use loaders like LABjs in FF4 or webkit.  To solve that problem, we should consider keeping the existing functionality or triggering the deprecated functionality when needed.&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
=== Response ===&lt;br /&gt;
&lt;br /&gt;
This is a valid point except that it assumes that all code that needs to be loaded is &amp;quot;modular&amp;quot;... in fact, most code on the internet that needs to be loaded is NOT modular, and instead requires particular ordering when being loaded... for instance, &amp;quot;jquery&amp;quot; and &amp;quot;jquery-ui&amp;quot; -- jQuery must be run before jQuery-UI is loaded and run.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The spirit of this proposal is to add the facility to native browser (rendering engine, specifically) behavior, such that any and all existing content is able to be loaded (even with dependencies and order) without modification.&lt;br /&gt;
&amp;lt;blockquote style=background-color:#eee&amp;gt;&lt;br /&gt;
Are we trying to codify how one would implement this HTML dynamically so I can achieve parallel loading but retain dependency that is inferred in the order? &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: white&amp;quot;&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery-ui.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If so, we must consider the case in which the dependency itself loads additional code which the discussions around `async=false` or even text/cache do not account for.  &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:23, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dependent code should be modular ===&lt;br /&gt;
&lt;br /&gt;
I completely agree, 99% of JavaScript in use today is NOT modular, but that&#039;s arguably because there was no built-in support to make it modular (IMHO, YMMV, RTFM, BBQ, ROFL).  But that doesn&#039;t mean there aren&#039;t dependencies that span script files / script nodes.  I don&#039;t know how many sites would be broken (or if there is any way to determine how many sites would be broken) if/when the latest browsers started loading and evaluating script-injected scripts out of order.  It&#039;s not just LABjs-based sites.  I&#039;ll bet many dojo and YUI sites will break, too (although I don&#039;t know this for a fact because I don&#039;t know exactly how their dynamic script loaders work).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;In any case, breaking existing sites is a BAD IDEA. :)  There should be some way to allow LABjs and other dynamic script loaders to continue to work.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The part I don&#039;t agree with in the proposals is that it should be the job of HTML and/or the browser engine to manage dependencies.  Specifically, I am talking about the scriptGroup element and the &amp;quot;waitFor&amp;quot; attribute.  The &amp;quot;async&amp;quot; attribute may be the right level: it appropriates only general heuristics to the browser: &#039;&#039;load these scripts whenever you like, but load these other scripts in this order&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Detailed dependency management belongs in the modules, though.  This is how it&#039;s done in most environments / languages: import statements, include statements, etc.  It&#039;s no different in JavaScript, if a developer wants to take advantage of some code in another module, she/he should import it into their current module.  This should be the model moving forward.  It&#039;s not hard, it&#039;s not un-web-like, and it&#039;s already being done.  &lt;br /&gt;
&lt;br /&gt;
Existing code can be made to work modularly, too:&lt;br /&gt;
&lt;br /&gt;
1. Identify modules and wrap them with a define() method.&lt;br /&gt;
2. Identify dependencies using either the [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition Asynchronous Module Definition] format or the CommonJS synchronous format&lt;br /&gt;
&lt;br /&gt;
async format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define([&#039;dependency1&#039;, &#039;dependency2&#039;], function (dependency1, dependency2) {&lt;br /&gt;
	/* this is the factory function, return the module inside here */&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sync format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define(function (require, exports, module) {&lt;br /&gt;
	/* this is the factory function, require dependencies and return the module inside here */&lt;br /&gt;
	var dependency1 = require(&#039;dependency1&#039;);&lt;br /&gt;
	var dependency2 = require(&#039;dependency2&#039;);&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the async case, the browser may employ whatever method it sees fit (e.g. parallel) to download the dependencies since the code inside the factory function won&#039;t execute until all of the dependencies are loaded and evaluated.  In the sync case, the browser has no choice but to download and evaluate the dependency before continuing code execution.  It&#039;s conceivable that the browser could find and asynchronously pre-fetch the inline require()&#039;ed dependencies in the sync case.  (RequireJS doesn&#039;t quite do this.  Instead I believe it finds the inline require() calls and converts the module to an async module.)  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;So, in short: don&#039;t break LABjs (or any other script loaders), but don&#039;t extend the spec to manage dependency management from HTML.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Response #2 ==&lt;br /&gt;
&lt;br /&gt;
The cat&#039;s already out of the bag... we&#039;ve got a dozen+ years worth, hundreds of millions of javascript files out there, which are NOT modular, and will not be modified to be modular. &lt;br /&gt;
&lt;br /&gt;
If we&#039;re talking about either trying to change all the JS on the web to be modular, or trying to extend the HTML markup spec to include a better facility for accomodating the existing script content, I think the former is idealistic and &amp;quot;correct&amp;quot; but the latter is realistic and &amp;quot;right&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
A modular loading system will only work for modular code, but a general loading mechanism in HTML (like the &amp;amp;lt;script&amp;gt; tag) can load both modular and non-modular code, which is why that more general mechanism is what&#039;s in HTML right now and not some more specialized loading API that only loads a small percentage of JavaScript code out there.&lt;br /&gt;
&lt;br /&gt;
The &amp;amp;lt;script&amp;gt; tag has worked fine forever, and there&#039;s been no real big push to do away with it in favor of having all loading handled by JavaScript -- in fact, that would be impossible because if you had no way to load JS onto the page with a &amp;amp;lt;script&amp;gt; tag, then no JavaScript could run on a page to load more code. So I don&#039;t agree that we should stop adding functionality to the HTML loading mechanism and only focus on JavaScript.&lt;br /&gt;
&lt;br /&gt;
If we agree that the &amp;amp;lt;script&amp;gt; tag itself is not only required but normative, then I&#039;m not sure why decorating the &amp;amp;lt;script&amp;gt; tag with additional behavior to help it be more powerful is a bad pattern. We&#039;ve addded &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; already. I&#039;m not sure I understand why adding a wrapper tag called &amp;quot;scriptGroup&amp;quot; would be that much different than attributes on the &amp;amp;lt;script&amp;gt; tag?&lt;br /&gt;
&lt;br /&gt;
I also don&#039;t think that &amp;quot;scriptGroup&amp;quot; constitutes &amp;quot;dependency management&amp;quot;. &amp;quot;scriptGroup&amp;quot; is a semantic way for a web author to express that they want to group a set of scripts together ONLY so far as execution order behavior is concerned. It implies nothing more to it (that &amp;quot;dependency management&amp;quot; would imply) than that.&lt;br /&gt;
&lt;br /&gt;
For instance, consider this: if JavaScript had been built with non-global context and statement level context and sandboxing and such things, we&#039;d have a much more secure JavaScript right now. But just because JavaScript may someday be taught some new tricks in terms of security, that doesn&#039;t mean that &amp;quot;now&amp;quot; HTML shouldn&#039;t try to help solve the problem. If for instance the &amp;amp;lt;frag&amp;gt; tag can be used to create a sandboxed environment for third-party JavaScript code to run in, this is a much easier way to address the security problem than to suggest we have to wait for ES-Harmony to add extra syntax to the language to accomplish the same thing.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 02:13, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Text/cache solution ==&lt;br /&gt;
&lt;br /&gt;
It seems to me that having a real text/cache script type, or a similar element that fires a load/error event and provides a .text property gets you where you need to be. You could setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/JavaScript&amp;quot;) or use the text to create a new script element. Or a new style element, or whatever. That puts you in control of when script or CSS is interpreted. With async as the default, you don&#039;t need a new ordered attribute as that&#039;s easily managed in script.&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;text/cache&amp;quot; response ==&lt;br /&gt;
&lt;br /&gt;
On the surface, this idea sounds like it&#039;s pretty similar to &amp;amp;lt;link rel=prefetch&amp;gt; -- in other words, we&#039;ve already standardized a way to prefetch a resource into cache, and probably in a better way than the hack that I did in LABjs of just relying on it fetching unrecognizable content.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it still suffers some similar problems to &amp;amp;lt;link rel=prefetch&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Firstly, if the notion is that you&#039;d use &amp;amp;lt;script type=&amp;quot;text/cache&amp;quot;&amp;gt; to prefetch, and then you&#039;d make a second request for the resource with a real &amp;amp;lt;script type=&amp;quot;text/javascript&amp;gt; node, it suffers the faulty assumption that the resource was served with proper cache headers.&lt;br /&gt;
&lt;br /&gt;
If we try to avoid the need for the second request by suggesting that you can access the `text` property of the node (and then eval() or inject that code when you want to execute it), this runs afoul of the same-origin policy problem if you requested the script from a non-local domain.&lt;br /&gt;
&lt;br /&gt;
The part of your suggestion that holds water would be if, given a &amp;quot;prefetched&amp;quot; script node that didn&#039;t execute yet, I could simply change that node&#039;s `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;, and that would explicitly trigger the browser to immediately execute it. &lt;br /&gt;
&lt;br /&gt;
This is an interesting idea. I can see though that it perhaps has some potential complications. &lt;br /&gt;
&lt;br /&gt;
For instance, would the browser have to keep a &amp;quot;hasExecuted&amp;quot; internal flag, so that changing the `type` value would only at most result in one execution? Also, if the script node in question is loaded but not executed, can the page alter the script code (by setting its `text` property) before making the change to the `type` value? In that case, should the browser execute the original code or the modified code? I can see security implications and confusion abounding in that behavior.&lt;br /&gt;
&lt;br /&gt;
Lastly, as mentioned above, this basically copies (in a similar but not exactly identical way) the &amp;amp;lt;link rel=prefetch&amp;gt; behavior. It may be seen as a negative to be trying to step on the toes of &amp;amp;lt;link rel=prefetch&amp;gt;, and also it may be more confusing to the general public as to why you&#039;d use one technique or the other, given their differences being so nuanced.&lt;br /&gt;
&lt;br /&gt;
That having been said, I can see that it&#039;s a viable alternate proposal. It&#039;s worth adding a note to that section of the main Wiki page and to getting some feedback from browser vendors on if they feel this is a more realistic/suitable solution to the use-case.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #eee&amp;quot;&amp;gt;&lt;br /&gt;
The difference between pre-fetching and this proposal seems pretty clear: Prefetching, if not performed now, will eventually be done once the user explicitly requests the page. while the &amp;quot;text/cache&amp;quot; solution indicates that the resource should load &#039;&#039;&#039;immediately&#039;&#039;&#039;, not during idle time. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:10, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 20:56, 4 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== RequireJS order support ==&lt;br /&gt;
&lt;br /&gt;
I am the main developer for RequireJS, and just want to voice my support for a solution that works on the script element itself, either by leveraging the async attribute or allowing something like an &amp;quot;order&amp;quot; boolean attribute that would allow specifying a dynamically added script element should be executed in the order that it appears in the DOM. This capability should be something can be capability detected to avoid browser sniffing.&lt;br /&gt;
&lt;br /&gt;
There are many scripts on the web today that have implicit dependencies that should be loaded in a specific order, but the application developer will want to use dynamically created script elements for best performance. jQuery plugins that depend on the jQuery script already been executed in the page are a good example.&lt;br /&gt;
&lt;br /&gt;
- James Burke&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5623</id>
		<title>Talk:Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5623"/>
		<updated>2010-12-15T19:23:37Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* Response */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please discuss the proposal here. All informal feedback is welcomed, and when it&#039;s appropriate, please add content to the main page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What about CommonJS / RequireJS? ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m not sure we need to complicate the HTML or browser engines in order to satisfy the advanced use cases.  To me it seems that the JavaScript langauge itself could abstract the requirements and let the browser vendors implement whatever solution they see fit.  Specifically, if JavaScript provided the define() and require() calls proposed in the CommonJS &amp;quot;specifications&amp;quot; (and implemented by [http://requirejs.org/docs/api.html RequireJS], [http://svn.dojotoolkit.org/src/dojo/trunk/_base/_loader/loader.js dojo (trunk)], and others *Yabble?), then browsers could just load and evaluate scripts as fast as possible without regard to script execution order.  &lt;br /&gt;
&lt;br /&gt;
This would solve all of the problems except for the current inability to use loaders like LABjs in FF4 or webkit.  To solve that problem, we should consider keeping the existing functionality or triggering the deprecated functionality when needed.&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
=== Response ===&lt;br /&gt;
&lt;br /&gt;
This is a valid point except that it assumes that all code that needs to be loaded is &amp;quot;modular&amp;quot;... in fact, most code on the internet that needs to be loaded is NOT modular, and instead requires particular ordering when being loaded... for instance, &amp;quot;jquery&amp;quot; and &amp;quot;jquery-ui&amp;quot; -- jQuery must be run before jQuery-UI is loaded and run.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The spirit of this proposal is to add the facility to native browser (rendering engine, specifically) behavior, such that any and all existing content is able to be loaded (even with dependencies and order) without modification.&lt;br /&gt;
&amp;lt;blockquote style=background-color:#eee&amp;gt;&lt;br /&gt;
Correct me if I&#039;m wrong, but are we trying to define the means by which script tags can be transitioned so they can be dynamically loaded?  In other words, are we trying to codify how I would implement this HTML dynamically?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: white&amp;quot;&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &amp;lt;br/&amp;gt; &lt;br /&gt;
&amp;amp;lt;script src=&amp;quot;jquery-ui.js&amp;quot;&amp;amp;gt; &amp;amp;lt;/script&amp;amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:23, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dependent code should be modular ===&lt;br /&gt;
&lt;br /&gt;
I completely agree, 99% of JavaScript in use today is NOT modular, but that&#039;s arguably because there was no built-in support to make it modular (IMHO, YMMV, RTFM, BBQ, ROFL).  But that doesn&#039;t mean there aren&#039;t dependencies that span script files / script nodes.  I don&#039;t know how many sites would be broken (or if there is any way to determine how many sites would be broken) if/when the latest browsers started loading and evaluating script-injected scripts out of order.  It&#039;s not just LABjs-based sites.  I&#039;ll bet many dojo and YUI sites will break, too (although I don&#039;t know this for a fact because I don&#039;t know exactly how their dynamic script loaders work).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;In any case, breaking existing sites is a BAD IDEA. :)  There should be some way to allow LABjs and other dynamic script loaders to continue to work.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The part I don&#039;t agree with in the proposals is that it should be the job of HTML and/or the browser engine to manage dependencies.  Specifically, I am talking about the scriptGroup element and the &amp;quot;waitFor&amp;quot; attribute.  The &amp;quot;async&amp;quot; attribute may be the right level: it appropriates only general heuristics to the browser: &#039;&#039;load these scripts whenever you like, but load these other scripts in this order&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Detailed dependency management belongs in the modules, though.  This is how it&#039;s done in most environments / languages: import statements, include statements, etc.  It&#039;s no different in JavaScript, if a developer wants to take advantage of some code in another module, she/he should import it into their current module.  This should be the model moving forward.  It&#039;s not hard, it&#039;s not un-web-like, and it&#039;s already being done.  &lt;br /&gt;
&lt;br /&gt;
Existing code can be made to work modularly, too:&lt;br /&gt;
&lt;br /&gt;
1. Identify modules and wrap them with a define() method.&lt;br /&gt;
2. Identify dependencies using either the [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition Asynchronous Module Definition] format or the CommonJS synchronous format&lt;br /&gt;
&lt;br /&gt;
async format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define([&#039;dependency1&#039;, &#039;dependency2&#039;], function (dependency1, dependency2) {&lt;br /&gt;
	/* this is the factory function, return the module inside here */&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sync format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define(function (require, exports, module) {&lt;br /&gt;
	/* this is the factory function, require dependencies and return the module inside here */&lt;br /&gt;
	var dependency1 = require(&#039;dependency1&#039;);&lt;br /&gt;
	var dependency2 = require(&#039;dependency2&#039;);&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the async case, the browser may employ whatever method it sees fit (e.g. parallel) to download the dependencies since the code inside the factory function won&#039;t execute until all of the dependencies are loaded and evaluated.  In the sync case, the browser has no choice but to download and evaluate the dependency before continuing code execution.  It&#039;s conceivable that the browser could find and asynchronously pre-fetch the inline require()&#039;ed dependencies in the sync case.  (RequireJS doesn&#039;t quite do this.  Instead I believe it finds the inline require() calls and converts the module to an async module.)  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;So, in short: don&#039;t break LABjs (or any other script loaders), but don&#039;t extend the spec to manage dependency management from HTML.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Response #2 ==&lt;br /&gt;
&lt;br /&gt;
The cat&#039;s already out of the bag... we&#039;ve got a dozen+ years worth, hundreds of millions of javascript files out there, which are NOT modular, and will not be modified to be modular. &lt;br /&gt;
&lt;br /&gt;
If we&#039;re talking about either trying to change all the JS on the web to be modular, or trying to extend the HTML markup spec to include a better facility for accomodating the existing script content, I think the former is idealistic and &amp;quot;correct&amp;quot; but the latter is realistic and &amp;quot;right&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
A modular loading system will only work for modular code, but a general loading mechanism in HTML (like the &amp;amp;lt;script&amp;gt; tag) can load both modular and non-modular code, which is why that more general mechanism is what&#039;s in HTML right now and not some more specialized loading API that only loads a small percentage of JavaScript code out there.&lt;br /&gt;
&lt;br /&gt;
The &amp;amp;lt;script&amp;gt; tag has worked fine forever, and there&#039;s been no real big push to do away with it in favor of having all loading handled by JavaScript -- in fact, that would be impossible because if you had no way to load JS onto the page with a &amp;amp;lt;script&amp;gt; tag, then no JavaScript could run on a page to load more code. So I don&#039;t agree that we should stop adding functionality to the HTML loading mechanism and only focus on JavaScript.&lt;br /&gt;
&lt;br /&gt;
If we agree that the &amp;amp;lt;script&amp;gt; tag itself is not only required but normative, then I&#039;m not sure why decorating the &amp;amp;lt;script&amp;gt; tag with additional behavior to help it be more powerful is a bad pattern. We&#039;ve addded &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; already. I&#039;m not sure I understand why adding a wrapper tag called &amp;quot;scriptGroup&amp;quot; would be that much different than attributes on the &amp;amp;lt;script&amp;gt; tag?&lt;br /&gt;
&lt;br /&gt;
I also don&#039;t think that &amp;quot;scriptGroup&amp;quot; constitutes &amp;quot;dependency management&amp;quot;. &amp;quot;scriptGroup&amp;quot; is a semantic way for a web author to express that they want to group a set of scripts together ONLY so far as execution order behavior is concerned. It implies nothing more to it (that &amp;quot;dependency management&amp;quot; would imply) than that.&lt;br /&gt;
&lt;br /&gt;
For instance, consider this: if JavaScript had been built with non-global context and statement level context and sandboxing and such things, we&#039;d have a much more secure JavaScript right now. But just because JavaScript may someday be taught some new tricks in terms of security, that doesn&#039;t mean that &amp;quot;now&amp;quot; HTML shouldn&#039;t try to help solve the problem. If for instance the &amp;amp;lt;frag&amp;gt; tag can be used to create a sandboxed environment for third-party JavaScript code to run in, this is a much easier way to address the security problem than to suggest we have to wait for ES-Harmony to add extra syntax to the language to accomplish the same thing.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 02:13, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Text/cache solution ==&lt;br /&gt;
&lt;br /&gt;
It seems to me that having a real text/cache script type, or a similar element that fires a load/error event and provides a .text property gets you where you need to be. You could setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/JavaScript&amp;quot;) or use the text to create a new script element. Or a new style element, or whatever. That puts you in control of when script or CSS is interpreted. With async as the default, you don&#039;t need a new ordered attribute as that&#039;s easily managed in script.&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;text/cache&amp;quot; response ==&lt;br /&gt;
&lt;br /&gt;
On the surface, this idea sounds like it&#039;s pretty similar to &amp;amp;lt;link rel=prefetch&amp;gt; -- in other words, we&#039;ve already standardized a way to prefetch a resource into cache, and probably in a better way than the hack that I did in LABjs of just relying on it fetching unrecognizable content.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it still suffers some similar problems to &amp;amp;lt;link rel=prefetch&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Firstly, if the notion is that you&#039;d use &amp;amp;lt;script type=&amp;quot;text/cache&amp;quot;&amp;gt; to prefetch, and then you&#039;d make a second request for the resource with a real &amp;amp;lt;script type=&amp;quot;text/javascript&amp;gt; node, it suffers the faulty assumption that the resource was served with proper cache headers.&lt;br /&gt;
&lt;br /&gt;
If we try to avoid the need for the second request by suggesting that you can access the `text` property of the node (and then eval() or inject that code when you want to execute it), this runs afoul of the same-origin policy problem if you requested the script from a non-local domain.&lt;br /&gt;
&lt;br /&gt;
The part of your suggestion that holds water would be if, given a &amp;quot;prefetched&amp;quot; script node that didn&#039;t execute yet, I could simply change that node&#039;s `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;, and that would explicitly trigger the browser to immediately execute it. &lt;br /&gt;
&lt;br /&gt;
This is an interesting idea. I can see though that it perhaps has some potential complications. &lt;br /&gt;
&lt;br /&gt;
For instance, would the browser have to keep a &amp;quot;hasExecuted&amp;quot; internal flag, so that changing the `type` value would only at most result in one execution? Also, if the script node in question is loaded but not executed, can the page alter the script code (by setting its `text` property) before making the change to the `type` value? In that case, should the browser execute the original code or the modified code? I can see security implications and confusion abounding in that behavior.&lt;br /&gt;
&lt;br /&gt;
Lastly, as mentioned above, this basically copies (in a similar but not exactly identical way) the &amp;amp;lt;link rel=prefetch&amp;gt; behavior. It may be seen as a negative to be trying to step on the toes of &amp;amp;lt;link rel=prefetch&amp;gt;, and also it may be more confusing to the general public as to why you&#039;d use one technique or the other, given their differences being so nuanced.&lt;br /&gt;
&lt;br /&gt;
That having been said, I can see that it&#039;s a viable alternate proposal. It&#039;s worth adding a note to that section of the main Wiki page and to getting some feedback from browser vendors on if they feel this is a more realistic/suitable solution to the use-case.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #eee&amp;quot;&amp;gt;&lt;br /&gt;
The difference between pre-fetching and this proposal seems pretty clear: Prefetching, if not performed now, will eventually be done once the user explicitly requests the page. while the &amp;quot;text/cache&amp;quot; solution indicates that the resource should load &#039;&#039;&#039;immediately&#039;&#039;&#039;, not during idle time. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:10, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 20:56, 4 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== RequireJS order support ==&lt;br /&gt;
&lt;br /&gt;
I am the main developer for RequireJS, and just want to voice my support for a solution that works on the script element itself, either by leveraging the async attribute or allowing something like an &amp;quot;order&amp;quot; boolean attribute that would allow specifying a dynamically added script element should be executed in the order that it appears in the DOM. This capability should be something can be capability detected to avoid browser sniffing.&lt;br /&gt;
&lt;br /&gt;
There are many scripts on the web today that have implicit dependencies that should be loaded in a specific order, but the application developer will want to use dynamically created script elements for best performance. jQuery plugins that depend on the jQuery script already been executed in the page are a good example.&lt;br /&gt;
&lt;br /&gt;
- James Burke&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5622</id>
		<title>Talk:Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Talk:Dynamic_Script_Execution_Order&amp;diff=5622"/>
		<updated>2010-12-15T19:10:08Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* &amp;quot;text/cache&amp;quot; response */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please discuss the proposal here. All informal feedback is welcomed, and when it&#039;s appropriate, please add content to the main page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What about CommonJS / RequireJS? ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m not sure we need to complicate the HTML or browser engines in order to satisfy the advanced use cases.  To me it seems that the JavaScript langauge itself could abstract the requirements and let the browser vendors implement whatever solution they see fit.  Specifically, if JavaScript provided the define() and require() calls proposed in the CommonJS &amp;quot;specifications&amp;quot; (and implemented by [http://requirejs.org/docs/api.html RequireJS], [http://svn.dojotoolkit.org/src/dojo/trunk/_base/_loader/loader.js dojo (trunk)], and others *Yabble?), then browsers could just load and evaluate scripts as fast as possible without regard to script execution order.  &lt;br /&gt;
&lt;br /&gt;
This would solve all of the problems except for the current inability to use loaders like LABjs in FF4 or webkit.  To solve that problem, we should consider keeping the existing functionality or triggering the deprecated functionality when needed.&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
=== Response ===&lt;br /&gt;
&lt;br /&gt;
This is a valid point except that it assumes that all code that needs to be loaded is &amp;quot;modular&amp;quot;... in fact, most code on the internet that needs to be loaded is NOT modular, and instead requires particular ordering when being loaded... for instance, &amp;quot;jquery&amp;quot; and &amp;quot;jquery-ui&amp;quot; -- jQuery must be run before jQuery-UI is loaded and run.&lt;br /&gt;
&lt;br /&gt;
The spirit of this proposal is to add the facility to native browser (rendering engine, specifically) behavior, such that any and all existing content is able to be loaded (even with dependencies and order) without modification.&lt;br /&gt;
&lt;br /&gt;
=== Dependent code should be modular ===&lt;br /&gt;
&lt;br /&gt;
I completely agree, 99% of JavaScript in use today is NOT modular, but that&#039;s arguably because there was no built-in support to make it modular (IMHO, YMMV, RTFM, BBQ, ROFL).  But that doesn&#039;t mean there aren&#039;t dependencies that span script files / script nodes.  I don&#039;t know how many sites would be broken (or if there is any way to determine how many sites would be broken) if/when the latest browsers started loading and evaluating script-injected scripts out of order.  It&#039;s not just LABjs-based sites.  I&#039;ll bet many dojo and YUI sites will break, too (although I don&#039;t know this for a fact because I don&#039;t know exactly how their dynamic script loaders work).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;In any case, breaking existing sites is a BAD IDEA. :)  There should be some way to allow LABjs and other dynamic script loaders to continue to work.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The part I don&#039;t agree with in the proposals is that it should be the job of HTML and/or the browser engine to manage dependencies.  Specifically, I am talking about the scriptGroup element and the &amp;quot;waitFor&amp;quot; attribute.  The &amp;quot;async&amp;quot; attribute may be the right level: it appropriates only general heuristics to the browser: &#039;&#039;load these scripts whenever you like, but load these other scripts in this order&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Detailed dependency management belongs in the modules, though.  This is how it&#039;s done in most environments / languages: import statements, include statements, etc.  It&#039;s no different in JavaScript, if a developer wants to take advantage of some code in another module, she/he should import it into their current module.  This should be the model moving forward.  It&#039;s not hard, it&#039;s not un-web-like, and it&#039;s already being done.  &lt;br /&gt;
&lt;br /&gt;
Existing code can be made to work modularly, too:&lt;br /&gt;
&lt;br /&gt;
1. Identify modules and wrap them with a define() method.&lt;br /&gt;
2. Identify dependencies using either the [http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition Asynchronous Module Definition] format or the CommonJS synchronous format&lt;br /&gt;
&lt;br /&gt;
async format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define([&#039;dependency1&#039;, &#039;dependency2&#039;], function (dependency1, dependency2) {&lt;br /&gt;
	/* this is the factory function, return the module inside here */&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sync format:&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
define(function (require, exports, module) {&lt;br /&gt;
	/* this is the factory function, require dependencies and return the module inside here */&lt;br /&gt;
	var dependency1 = require(&#039;dependency1&#039;);&lt;br /&gt;
	var dependency2 = require(&#039;dependency2&#039;);&lt;br /&gt;
	return { /* some object, but could also be a constructor or a function */ };&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the async case, the browser may employ whatever method it sees fit (e.g. parallel) to download the dependencies since the code inside the factory function won&#039;t execute until all of the dependencies are loaded and evaluated.  In the sync case, the browser has no choice but to download and evaluate the dependency before continuing code execution.  It&#039;s conceivable that the browser could find and asynchronously pre-fetch the inline require()&#039;ed dependencies in the sync case.  (RequireJS doesn&#039;t quite do this.  Instead I believe it finds the inline require() calls and converts the module to an async module.)  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;So, in short: don&#039;t break LABjs (or any other script loaders), but don&#039;t extend the spec to manage dependency management from HTML.&#039;&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
--[[User:Unscriptable|Unscriptable]] 01:29, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Response #2 ==&lt;br /&gt;
&lt;br /&gt;
The cat&#039;s already out of the bag... we&#039;ve got a dozen+ years worth, hundreds of millions of javascript files out there, which are NOT modular, and will not be modified to be modular. &lt;br /&gt;
&lt;br /&gt;
If we&#039;re talking about either trying to change all the JS on the web to be modular, or trying to extend the HTML markup spec to include a better facility for accomodating the existing script content, I think the former is idealistic and &amp;quot;correct&amp;quot; but the latter is realistic and &amp;quot;right&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
A modular loading system will only work for modular code, but a general loading mechanism in HTML (like the &amp;amp;lt;script&amp;gt; tag) can load both modular and non-modular code, which is why that more general mechanism is what&#039;s in HTML right now and not some more specialized loading API that only loads a small percentage of JavaScript code out there.&lt;br /&gt;
&lt;br /&gt;
The &amp;amp;lt;script&amp;gt; tag has worked fine forever, and there&#039;s been no real big push to do away with it in favor of having all loading handled by JavaScript -- in fact, that would be impossible because if you had no way to load JS onto the page with a &amp;amp;lt;script&amp;gt; tag, then no JavaScript could run on a page to load more code. So I don&#039;t agree that we should stop adding functionality to the HTML loading mechanism and only focus on JavaScript.&lt;br /&gt;
&lt;br /&gt;
If we agree that the &amp;amp;lt;script&amp;gt; tag itself is not only required but normative, then I&#039;m not sure why decorating the &amp;amp;lt;script&amp;gt; tag with additional behavior to help it be more powerful is a bad pattern. We&#039;ve addded &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; already. I&#039;m not sure I understand why adding a wrapper tag called &amp;quot;scriptGroup&amp;quot; would be that much different than attributes on the &amp;amp;lt;script&amp;gt; tag?&lt;br /&gt;
&lt;br /&gt;
I also don&#039;t think that &amp;quot;scriptGroup&amp;quot; constitutes &amp;quot;dependency management&amp;quot;. &amp;quot;scriptGroup&amp;quot; is a semantic way for a web author to express that they want to group a set of scripts together ONLY so far as execution order behavior is concerned. It implies nothing more to it (that &amp;quot;dependency management&amp;quot; would imply) than that.&lt;br /&gt;
&lt;br /&gt;
For instance, consider this: if JavaScript had been built with non-global context and statement level context and sandboxing and such things, we&#039;d have a much more secure JavaScript right now. But just because JavaScript may someday be taught some new tricks in terms of security, that doesn&#039;t mean that &amp;quot;now&amp;quot; HTML shouldn&#039;t try to help solve the problem. If for instance the &amp;amp;lt;frag&amp;gt; tag can be used to create a sandboxed environment for third-party JavaScript code to run in, this is a much easier way to address the security problem than to suggest we have to wait for ES-Harmony to add extra syntax to the language to accomplish the same thing.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 02:13, 2 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Text/cache solution ==&lt;br /&gt;
&lt;br /&gt;
It seems to me that having a real text/cache script type, or a similar element that fires a load/error event and provides a .text property gets you where you need to be. You could setAttribute(&amp;quot;type&amp;quot;, &amp;quot;text/JavaScript&amp;quot;) or use the text to create a new script element. Or a new style element, or whatever. That puts you in control of when script or CSS is interpreted. With async as the default, you don&#039;t need a new ordered attribute as that&#039;s easily managed in script.&lt;br /&gt;
&lt;br /&gt;
== &amp;quot;text/cache&amp;quot; response ==&lt;br /&gt;
&lt;br /&gt;
On the surface, this idea sounds like it&#039;s pretty similar to &amp;amp;lt;link rel=prefetch&amp;gt; -- in other words, we&#039;ve already standardized a way to prefetch a resource into cache, and probably in a better way than the hack that I did in LABjs of just relying on it fetching unrecognizable content.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it still suffers some similar problems to &amp;amp;lt;link rel=prefetch&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Firstly, if the notion is that you&#039;d use &amp;amp;lt;script type=&amp;quot;text/cache&amp;quot;&amp;gt; to prefetch, and then you&#039;d make a second request for the resource with a real &amp;amp;lt;script type=&amp;quot;text/javascript&amp;gt; node, it suffers the faulty assumption that the resource was served with proper cache headers.&lt;br /&gt;
&lt;br /&gt;
If we try to avoid the need for the second request by suggesting that you can access the `text` property of the node (and then eval() or inject that code when you want to execute it), this runs afoul of the same-origin policy problem if you requested the script from a non-local domain.&lt;br /&gt;
&lt;br /&gt;
The part of your suggestion that holds water would be if, given a &amp;quot;prefetched&amp;quot; script node that didn&#039;t execute yet, I could simply change that node&#039;s `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;, and that would explicitly trigger the browser to immediately execute it. &lt;br /&gt;
&lt;br /&gt;
This is an interesting idea. I can see though that it perhaps has some potential complications. &lt;br /&gt;
&lt;br /&gt;
For instance, would the browser have to keep a &amp;quot;hasExecuted&amp;quot; internal flag, so that changing the `type` value would only at most result in one execution? Also, if the script node in question is loaded but not executed, can the page alter the script code (by setting its `text` property) before making the change to the `type` value? In that case, should the browser execute the original code or the modified code? I can see security implications and confusion abounding in that behavior.&lt;br /&gt;
&lt;br /&gt;
Lastly, as mentioned above, this basically copies (in a similar but not exactly identical way) the &amp;amp;lt;link rel=prefetch&amp;gt; behavior. It may be seen as a negative to be trying to step on the toes of &amp;amp;lt;link rel=prefetch&amp;gt;, and also it may be more confusing to the general public as to why you&#039;d use one technique or the other, given their differences being so nuanced.&lt;br /&gt;
&lt;br /&gt;
That having been said, I can see that it&#039;s a viable alternate proposal. It&#039;s worth adding a note to that section of the main Wiki page and to getting some feedback from browser vendors on if they feel this is a more realistic/suitable solution to the use-case.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #eee&amp;quot;&amp;gt;&lt;br /&gt;
The difference between pre-fetching and this proposal seems pretty clear: Prefetching, if not performed now, will eventually be done once the user explicitly requests the page. while the &amp;quot;text/cache&amp;quot; solution indicates that the resource should load &#039;&#039;&#039;immediately&#039;&#039;&#039;, not during idle time. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt; &lt;br /&gt;
[[User:Serverherder|Serverherder]] 19:10, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 20:56, 4 November 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== RequireJS order support ==&lt;br /&gt;
&lt;br /&gt;
I am the main developer for RequireJS, and just want to voice my support for a solution that works on the script element itself, either by leveraging the async attribute or allowing something like an &amp;quot;order&amp;quot; boolean attribute that would allow specifying a dynamically added script element should be executed in the order that it appears in the DOM. This capability should be something can be capability detected to avoid browser sniffing.&lt;br /&gt;
&lt;br /&gt;
There are many scripts on the web today that have implicit dependencies that should be loaded in a specific order, but the application developer will want to use dynamically created script elements for best performance. jQuery plugins that depend on the jQuery script already been executed in the page are a good example.&lt;br /&gt;
&lt;br /&gt;
- James Burke&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=User:Serverherder&amp;diff=5621</id>
		<title>User:Serverherder</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=User:Serverherder&amp;diff=5621"/>
		<updated>2010-12-15T18:57:06Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: Created page with &amp;#039;[http://digital-fulcrum.com/ Digital Fulcrum]&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://digital-fulcrum.com/ Digital Fulcrum]&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Dynamic_Script_Execution_Order&amp;diff=5620</id>
		<title>Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Dynamic_Script_Execution_Order&amp;diff=5620"/>
		<updated>2010-12-15T18:49:29Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* My Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is intended to formalize the discussion around an important but currently underserved use-case (in both spec and various browser implementations): the need for a dynamic script loading facility that can download resources in parallel but ensure that they execute serially in insertion order, for dependency reasons.&lt;br /&gt;
&lt;br /&gt;
A long email thread on the W3C public-html list, which began [http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html here] and for which a recent message is [http://lists.w3.org/Archives/Public/public-html/2010Oct/0415.html here], has been discussing this problem, but the email thread is becoming unruly and hard to track, so this wiki page will now be the official location to discuss the topic.&lt;br /&gt;
&lt;br /&gt;
Briefly, this issue has arisen because recent &amp;quot;nightlies&amp;quot; changes in both Mozilla Gecko and Webkit have broken the ability for script-loaders like [http://labjs.com LABjs] to be able to download scripts in parallel but ensure their execution order. As a result of the discussion, it&#039;s become apparent that both the spec for, and various current browser implementations around, dynamic script loading is incomplete in addressing this use case, and that some change needs to occur.&lt;br /&gt;
&lt;br /&gt;
There is one main proposal that has surfaced from the discussions, with several other alternatives having been discussed. This page will try to distill the long email thread down and clearly present the main proposal, objections, and alternative suggestions.&lt;br /&gt;
&lt;br /&gt;
Please feel free to join the discussion of this topic in the [[Talk:Dynamic_Script_Execution_Order]] area.&lt;br /&gt;
&lt;br /&gt;
== Use Case Description ==&lt;br /&gt;
Script tags/elements can either: &lt;br /&gt;
&lt;br /&gt;
a) appear in the HTML markup (&amp;quot;parser-inserted&amp;quot;), OR&lt;br /&gt;
&lt;br /&gt;
b) be dynamically appended to the DOM using document.createElement() (&amp;quot;script-inserted&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Parser-inserted script tags, up until recent browser versions, had the undesirable performance behavior of loading and executing serially, blocking everything else while doing so. Recently, many browsers have improved the situation by loading the scripts in parallel, but still executing them in order.&lt;br /&gt;
&lt;br /&gt;
On-demand (or dynamic) script loading has emerged in recent years for a variety of different reasons, most notably the performance improvements to address such concerns. It is desired by many different scenarios to be able to download scripts to a page completely independently of the loading of the rest of a page&#039;s resources, or even well after a page has finished loading (&amp;quot;on-demand&amp;quot;).  &lt;br /&gt;
&lt;br /&gt;
Recent additions to HTML spec such as &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; were intended to address the use-case for parser-inserted script elements, but their behaviors have been unhelpful for the on-demand loading use-case (script-inserted script elements).&lt;br /&gt;
&lt;br /&gt;
Thus, script loaders (like [http://labjs.com LABjs]) were developed to give page authors an easy way to specify one or more scripts to load (regardless of when in the life-time of the page that loading is requested), and for as many of them as possible to load in parallel, and for those scripts to be loadable from any local or remote domain location, and for the script loader to be able to control the execution order (if the usage of the script loader&#039;s API expresses the need to) to preserve dependencies between the scripts.&lt;br /&gt;
&lt;br /&gt;
Sometimes, dynamic script loading is used to load totally independent scripts, and thus &amp;quot;as fast as possible&amp;quot; execution is desired. Other times (and possibly more frequently), multiple scripts are loaded with some  dependencies among them, requiring them to execute in a certain order. &lt;br /&gt;
&lt;br /&gt;
What is needed is some facility by which a script loader can express that dynamic script loading either does or does not need execution order preserved among the queue of requested script loadings.&lt;br /&gt;
&lt;br /&gt;
=== Current Limitations ===&lt;br /&gt;
Unfortunately, browser behavior around script-inserted script elements and their loading and execution behavior is splintered. There are, at present, two main camps of behavior:&lt;br /&gt;
&lt;br /&gt;
a) in IE and Webkit (including Chrome), the default behavior for script-inserted script elements is for them all to execute in &amp;quot;as fast as possible&amp;quot; mode, meaning there&#039;s no guarantee about ordering. This effectively makes on-demand (dynamic) script loading impossible to work in parallel-mode if the resources in question have dependencies -- the only straight-forward way to handle things is to load each file and execute, serially, losing the parallel loading performance benefits.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
I&#039;m not sure if this is the case.  &lt;br /&gt;
&lt;br /&gt;
IE will start fetching resources without execution simply by setting the src attribute.  Scripts will not execute, however, until they are added to the document.  Since IE supports the readyState attribute and readystatechange event, it&#039;s possible to load scripts in parallel and execute them in order without resorting to invalid type attribute hack-ery.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:white&amp;quot; lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
script= document.createElement(&amp;quot;SCRIPT&amp;quot;); &lt;br /&gt;
script.onreadystatechange= function(){ &lt;br /&gt;
    if(this.readyState == &#039;loaded&#039;)&lt;br /&gt;
          /* &lt;br /&gt;
             Network fetch is now complete, following&lt;br /&gt;
             triggers synchronous execution.  &lt;br /&gt;
          */&lt;br /&gt;
          document.body.appendChild(this); &lt;br /&gt;
    else if(this.readyState == &amp;quot;complete&amp;quot;)&lt;br /&gt;
          this.onreadystatechange= null; &lt;br /&gt;
}&lt;br /&gt;
script.src= &amp;quot;foo.js&amp;quot;; &lt;br /&gt;
/* Network fetching begins now */&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #ccc&amp;quot;&amp;gt;&lt;br /&gt;
I&#039;ve experimented with such things heavily in the past, and I&#039;m fairly suspicious that this is not reliable across various versions of IE (6-9), nor does it work reliably the same depending on if an element is already in the browser cache or not. I&#039;m not 100% certain that what you suggest is flawed, but I have a strong hunch that it can be shown to have some holes in it for IE loading. I will try to create some test cases to prove or disprove.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
When loading a script that is in the cache, IE requires the event handler be installed prior to setting the `src` attribute.  Otherwise the element&#039;s transition to the &amp;quot;loaded&amp;quot; state will be missed.  IE routinely &amp;quot;skips&amp;quot; ready state transitions when cached scripts are immediately inserted into the DOM so suspicion is understandable; however, delayed insertion works around this &amp;quot;problem&amp;quot;.  The script above has been tested in IE6-8 with scripts in a variety of caching states and found to work correctly. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Moreover, you&#039;re suggesting something that is AFAIK only IE right now, and definitely appears to not be standardized. In the same way that I&#039;m hesitant to continue pinning loading behavior on hacks like the invalid type attribute value, I wouldn&#039;t want to approach loading with this technique (even if it were proven reliable on all IE&#039;s under all caching circumstances) unless it was a serious proposal to the W3C to have this technique be the new standard (as opposed to the current proposal, as implemented by Mozilla and Webkit now).&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
I think you&#039;re right: Only IE impelements this event and property on script elements.  The readystatechange event, however, is widely understood due to the XmlHttpRequest implementation and `readyState` property has been added to the `document` in WebKit, Mozilla and IE. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
That having been said, I think this is at least a viable candidate for &amp;quot;Alternate Proposals&amp;quot; and deserves to be listed as such. As always, I welcome input from the community on all the ideas presented here, including this one. But, since the main proposal (async=false) is already being implemented by at least two major browsers, I&#039;m not sure if the tide will be changed or not.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color:#ddd;&amp;quot;&amp;gt;&lt;br /&gt;
Also, the suggestion of handling the &amp;quot;preload&amp;quot; and deferred execution via the script tag&#039;s `readyState` property is very similar in spirit to the suggestion that was made to explicitly support [[Dynamic_Script_Execution_Order#Explicit_support_for_.22text.2Fcache.22_MIME_type_behavior|preloading into cache without execution]]. As I said, either of those two approaches might work, but they both put more of the onus of complexity in managing multiple dependencies on the high-level code (author, script loader, etc). I&#039;m more in favor of this functionality being explicitly built-in natively into the queues. As always, I welcome comments to any side of this discussion.&lt;br /&gt;
&lt;br /&gt;
[[User:Getify|Getify]] 18:35, 15 December 2010 (UTC)&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
b) in Gecko and Opera, the default behavior for script-inserted script elements is for them all to load in parallel, but execute serially in insertion order. Technically, this makes it impossible to dynamically load independent script elements and have them execute in &amp;quot;as fast as possible&amp;quot; mode.&lt;br /&gt;
&lt;br /&gt;
As described above, both behaviors are desirable under different circumstances, but each of the two camps provides only one behavior, and no way to straightforwardly achieve the other. This obviously creates a big nightmare interoperability-wise when trying to provide a general script loader cross-browser.&lt;br /&gt;
&lt;br /&gt;
Since it is observed that the behavior in (a) is more detrimental (race-condition wise) for the case where dependencies exist, script loaders like LABjs had to find some way around this problem while still attempting the best possible parallel loading performance. However, the trick used is hacky and not completely reliable -- yet it is the best way to solve the use-case in &amp;lt;s&amp;gt;IE and &amp;lt;/s&amp;gt;Webkit. &lt;br /&gt;
&lt;br /&gt;
For Gecko/Opera, the concession was just (silently) made that the lesser-common use case of &amp;quot;as fast as possible&amp;quot; wasn&#039;t possible, but degraded fine to &amp;quot;insertion order execution&amp;quot;, while keeping the parallel loading benefits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
Gecko&#039;s strict execution order creates dependencies between scripts which are unrelated and prevents the ability mitigate the impact of server outages / network latency.  This is exacerbated by the fact that Gecko, unlike IE and WebKit, provides no mechanism to &amp;lt;b&amp;gt;remove&amp;lt;/b&amp;gt; scripts from the execution queue. &lt;br /&gt;
&lt;br /&gt;
Consider the case where JSONP is used to provide auto-completion.  The user types &amp;quot;hello&amp;quot; and the JSONP request is made; however, the &amp;quot;currently&amp;quot; loading script is out-of-date as soon as the user modifies his search to &amp;quot;hello world&amp;quot;.  Gecko&#039;s algorithm requires the out-of-date request load and execute before the second request.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Recently, Gecko landed a [http://hg.mozilla.org/mozilla-central/rev/a60414d076b5 patch] to the trunk that stopped Gecko&#039;s existing behavior of preserving execution order, making script-inserted script elements now execute in &amp;quot;as fast as possible&amp;quot; mode similiar to IE/Webkit. Unfortunately, the &amp;quot;workaround&amp;quot; used in IE/Webkit (described in the next section) for dealing with parallel loading and execution-order dependencies does not work in Gecko, which means presently the use-case in question is now broken in Gecko trunk/FF4 nightlies.&lt;br /&gt;
&lt;br /&gt;
Moreover, Webkit recently landed a [http://trac.webkit.org/changeset/67245 patch] to the trunk that stopped Webkit&#039;s non-standard but long-held behavior (also used in the &amp;quot;workaround&amp;quot; described in the next section) of loading into cache script resources with an unrecognized &amp;quot;type&amp;quot; value, but silently not executing them. This behvaior (while hacky) is central to being able to address the use-case in question in Webkit, so at present, Webkit nightlies are now also entirely broken on the use-case (though in a different way than Gecko).&lt;br /&gt;
&lt;br /&gt;
Both the Gecko change and the Webkit change are well-intentioned, as they are bringing the respective browser more in line with the HTML spec. However, what&#039;s really been demonstrated is that the HTML spec is not properly handling this use-case, and so the goal is not to address the browser issues raised with more awkward hacks, but to address the shortcomings of the spec first, and then encourage all browsers to adhere to such.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
Considering Internet Explorer&#039;s readyState implementation provides a means of both parallel loading and preserving execution order can be achieved, perhaps its &amp;quot;readyState&amp;quot; property and onreadystatechange event should be included. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Current Usage and Workarounds ===&lt;br /&gt;
To work around the limitation in IE/Webkit(prior to the above noted patch) of not being able to rely on script order execution for parallel loaded scripts, a &amp;quot;preloading&amp;quot; trick was developed. This trick relied on non-standard (but long-held) behavior in these browsers that a script-inserted script element with an unrecognized &amp;quot;type&amp;quot; value (such as &amp;quot;script/cache&amp;quot;) would be fetched/loaded, but would not execute. This had the effect of loading the resource into cache, and then firing the &amp;quot;load&amp;quot; handlers to let the page know when the resource was completely in cache. &lt;br /&gt;
&lt;br /&gt;
Assuming that the resource was served with proper caching headers, and was in fact in the cache, it could then be executed (nearly) immediately when it was the proper execution order time by re-requesting the same resource via another script-inserted script element with the proper &amp;quot;text/javascript&amp;quot; type value, pulling the resource from the cache and executing it, without another server round-trip.&lt;br /&gt;
&lt;br /&gt;
Of course, the assumption of proper cache headers is a huge one, and not at all reliable. Some recent estimates by performance optimization specialists have suggested as much as 70% of scripts across the internet are not served with proper caching headers, which means that such scripts would be completely ineffective if loaded using this (or a similar) technique. The script resource would end up being loaded completely a second-time, and the &amp;quot;near immediate&amp;quot; execution would obviously be false, and thus race conditions would ensue.&lt;br /&gt;
&lt;br /&gt;
It&#039;s important to note at this point that the new &amp;amp;lt;link rel=prefetch&amp;gt; facility has been suggested as a better workaround, but it suffers the same ill-fated assumption of script cacheability. Still others have suggested &amp;quot;new Image().src=...&amp;quot; or the [http://www.phpied.com/preload-then-execute/ &amp;amp;lt;object&amp;amp;gt; preloading trick] suggested by Stoyan Stefanov. Again, these tricks unwisely assume cacheability, for the &amp;quot;preloading&amp;quot; trick to solve the use-case in question.&lt;br /&gt;
&lt;br /&gt;
=== At Risk ===&lt;br /&gt;
Currently, there are several large/popular web sites which are either currently (or who intend to soon) use LABjs in such a way as to run afoul of the new Gecko and Webkit behavioral changes with LABjs failing to operate properly. It&#039;s important to note that the problems of race conditions can be subtle and hard to detect, and so merely loading up such sites and failing to observe overt failure is not sufficient.&lt;br /&gt;
&lt;br /&gt;
Sites which are known to have LABjs loading techniques in place with currently broken (or susceptible to such breakage in the near future) behavior are:&lt;br /&gt;
&lt;br /&gt;
* [http://twitter.com Twitter]&lt;br /&gt;
* [http://zappos.com Zappos]&lt;br /&gt;
* [http://vimeo.com Vimeo]&lt;br /&gt;
* [http://mefeedia.com MeFeedia]&lt;br /&gt;
* [http://blog.getify.com Getify Solutions blog (my blog)]&lt;br /&gt;
* [http://flensed.com flensed Flash+JavaScript browser shims (cross-domain Ajax, cross-browser cookies, etc)]&lt;br /&gt;
&lt;br /&gt;
Rather than getting hung up in the syntax of usage in LABjs that is or is not going to break, it&#039;s best to just think of the problem this way:&lt;br /&gt;
&lt;br /&gt;
Does a site need to load more than one script, at least one of which comes from a remote domain location (like a CDN), and for which among the scripts there&#039;s at least one execution-order dependency among them? If so, then that site is susceptible to the current/future breakage if the HTML spec (and browsers) do not address this use case.&lt;br /&gt;
&lt;br /&gt;
A common example (in use on many sites) of such might be loading:&lt;br /&gt;
&lt;br /&gt;
* jQuery from the CDN&lt;br /&gt;
* jQuery-UI from the CDN&lt;br /&gt;
* plugins and usage code in one or more local files&lt;br /&gt;
* Google Analytics from the Google domain&lt;br /&gt;
&lt;br /&gt;
Note that the emergence of popular script frameworks and their hosting on public CDN&#039;s is leading to more and more sites loading scripts from both local and remote locations, and also to loading more files that have dependencies (rather than the practice of concat&#039;ing all files into one file to avoid dependency issues).&lt;br /&gt;
&lt;br /&gt;
Any site which fits a profile like the above, and which might currently (many do), or in the future want to, use a script loader to improve their loading performance, will fail to achieve what they want cross-browser and in a performant way, if the HTML spec (and browsers) do not address the use case.&lt;br /&gt;
&lt;br /&gt;
=== Benefits ===&lt;br /&gt;
The benefits of addressing both behaviors directly (without &amp;quot;preloading&amp;quot; tricks and bad assumption reliance) have been implied in the above discussion, but in short are:&lt;br /&gt;
&lt;br /&gt;
a) clear and simplified code for script loaders, which leads to easier use by authors of more pages, which in turn leads to better web performance (as demonstrated clearly by intelligent script loading techniques as compared to just simple &amp;amp;lt;script&amp;gt; tags in HTML markup)&lt;br /&gt;
&lt;br /&gt;
b) full access to either/both of the execution-order behaviors (as the author sees fit), regardless of browser&lt;br /&gt;
&lt;br /&gt;
c) avoiding reliance on bad assumptions (like cacheability) as a sufficient way to address the use-case&lt;br /&gt;
&lt;br /&gt;
=== External Discussions of this Feature ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html W3C public-html email thread]&amp;lt;/cite&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://www.w3.org/Bugs/Public/show_bug.cgi?id=11295 W3C Bug #11295]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[https://bugzilla.mozilla.org/show_bug.cgi?id=602838 Mozilla Bug #602838]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[https://bugs.webkit.org/show_bug.cgi?id=50115 Webkit Bug #50115]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://hsivonen.iki.fi/script-execution/ HTML5 Script Execution Changes in Firefox 4 Beta 7]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://blog.getify.com/2010/10/labjs-w3c-brief-update/ LABjs and W3C... brief update]&amp;lt;/cite&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://blog.getify.com/2010/10/ff4-script-loaders-and-order-preservation/ FF4, script loaders, and order preservation]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proposed Solutions ==&lt;br /&gt;
&lt;br /&gt;
=== My Solution ===&lt;br /&gt;
The current proposal most well supported from the email discussion thread, and the one which I feel makes most sense, is described here.&lt;br /&gt;
&lt;br /&gt;
The HTML spec already defines the &amp;quot;async&amp;quot; attribute for parser-inserted script tags, which when set to &amp;quot;true&amp;quot;, changes their execution order behavior to be like script-inserted script-elements (in IE/Webkit), which is that they load in parallel and execute &amp;quot;as fast as possible&amp;quot; (ostensibly because the author is expressing no dependencies between multiple such &amp;quot;async&amp;quot;-marked scripts). Parser-inserted script elements without &amp;quot;async&amp;quot; (or with it set to false) behave as before and expected, which is that they load in parallel but execute in order.&lt;br /&gt;
&lt;br /&gt;
However, the HTML spec does not define the &amp;quot;async&amp;quot; property (or any such behavior) for script-inserted script nodes (such as those created by a script loader). Instead, the spec implies that &amp;quot;async=true&amp;quot; like behavior is always true for such script-inserted script elements.&lt;br /&gt;
&lt;br /&gt;
What is proposed is:&lt;br /&gt;
&lt;br /&gt;
a) Script-inserted script elements should have (and respect the value of) an &amp;quot;async&amp;quot; property which is basically identical to the &amp;quot;async&amp;quot; attribute for parser-inserted script elements. That is, script elements with the &amp;quot;async&amp;quot; property set to &amp;quot;true&amp;quot; will behave accordingly, as will script elements with the &amp;quot;async&amp;quot; property set to false. &lt;br /&gt;
&lt;br /&gt;
Essentially, the proposal is to mirror the &amp;quot;async&amp;quot; attribute behavior of parser-inserted script elements as an &amp;quot;async&amp;quot; property on script-inserted script elements. This has the benefit of using an existing facility and extending it (from current spec) in a way that is sensisble and symmetric with its current definition.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EFEFEF&amp;quot;&amp;gt;&lt;br /&gt;
The scriptgroup or `readyState`  alternate proposals allow for dependency management to be done in high-level code.  The singular syncrhonized execution queue proposed here introduces artificial dependencies, undermining some of the benefits dynamic script loading provides.  &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #ccc;&amp;quot;&amp;gt;&lt;br /&gt;
It&#039;s important to note that `async=false` scripts will load in a separate queue from `async=true` scripts. It&#039;s not that all scripts will now be forced into this insertion-order-execution queue. An author (or script loader) can chose which queue to put a script loading into based on the needs of the page and the resource. If I have a few scripts that are unrelated to each other and the main page (like Google Analytics, social sharing buttons, etc), I&#039;ll load those via `async=true`. For other scripts, where order matters for dependency sake, I&#039;ll use `async=false`. I think having both those queues available to high-level code is enough control over loading to serve the majority of use-cases pretty well.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EFEFEF&amp;quot;&amp;gt;&lt;br /&gt;
If at any point these services begin dynamically loading `async=false` scripts of their own, they will begin blocking.  This can lead to unexpected behavior of existing code as third-party libraries and services change.  It would seem the specification should provide a means by which this blocking can be isolated to dependencies defined by the author and ordered execution not introduce conditions that allow unrelated libraries to affect this.   &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b) Furthermore, to aid in &amp;quot;feature-detection&amp;quot; of such new behavior, the proposal is to have the default value for the &amp;quot;async&amp;quot; property of script-inserted script elements be &amp;quot;true&amp;quot; (and of course the associated behavior thereof).&lt;br /&gt;
&lt;br /&gt;
There are two major benefits to (b). One is that it provides a way to feature test such new behavior by not just looking for the existence of the &amp;quot;async&amp;quot; property on script elements, but specifically that the default value is &amp;quot;true&amp;quot; (which is opposite of what it would currently/normally be). Secondly, defaulting to &amp;quot;async=true&amp;quot; behavior for script-inserted script elements would preserve the default behavior of IE and Webkit, meaning there&#039;d be less of a chance of breaking existing web content in either of those two browsers.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also important to note that there is no implied or requested effect or dependency between script-inserted script elements and parser-inserted script elements -- the two types of scripts would load and execute in entirely separate behavioral sandboxes.&lt;br /&gt;
&lt;br /&gt;
==== Proposal Amendment: Events ====&lt;br /&gt;
In addition to standardizing how scripts load and execute, it&#039;s also important to standardize the load and error events, and under what circumstances they fire, etc. Without reliable load/error events, the main proposal is not reliable and is thus unhelpful for the use-case.&lt;br /&gt;
&lt;br /&gt;
A script-inserted script element must fire the &amp;quot;load&amp;quot; event only once, when:&lt;br /&gt;
&lt;br /&gt;
a) immediately after the resource finishes loading, but before parsing/execution, AND&lt;br /&gt;
&lt;br /&gt;
b) the script element loads any non-empty content (that is, it was a successful HTTP request), AND&lt;br /&gt;
&lt;br /&gt;
c) the script element has either loaded from the remote location, or is loaded from the brower cache&lt;br /&gt;
&lt;br /&gt;
Specifically, the script &amp;quot;load&amp;quot; event must come immediately between the script element finishing loading and the script element being parsed/executed. If the script resource successfully loads, nothing should interrupt the sequence of fininshing loading, the &amp;quot;load&amp;quot; event firing, and the script being parsed/executed.&lt;br /&gt;
&lt;br /&gt;
A script-inserted script element must fire the &amp;quot;error&amp;quot; event only once, when:&lt;br /&gt;
&lt;br /&gt;
a) immediately after a loading failure for the resource is detected (that is, an HTTP error received, such as 404, 500, 503, etc).&lt;br /&gt;
&lt;br /&gt;
Either the &amp;quot;load&amp;quot; or &amp;quot;error&amp;quot; event, but not both, will fire, and only once, for every script-inserted script element.&lt;br /&gt;
&lt;br /&gt;
NOTE: &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events on script-inserted script elements must fire synchronously to ensure event reliability.&lt;br /&gt;
&lt;br /&gt;
A case may be made for adding the &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events as described here to parser-inserted script elements as well.&lt;br /&gt;
&lt;br /&gt;
==== Processing Model ====&lt;br /&gt;
Script inserted script elements will have an &amp;quot;async&amp;quot; property that defaults to &amp;quot;true&amp;quot;. If the author does not change the value, all such requested script loadings will be in their own &amp;quot;queue&amp;quot; and will default to &amp;quot;as fast as possible&amp;quot; execution behavior. For any script elements that the author sets &amp;quot;async=false&amp;quot;, those scripts will load in a separate &amp;quot;queue&amp;quot;, and will execute in insertion order only. Again, these two &amp;quot;queues&amp;quot; will operate strictly independent of each other.&lt;br /&gt;
&lt;br /&gt;
==== Processing Model Details (without the event amendment) ====&lt;br /&gt;
&lt;br /&gt;
When a script element node is created, if it is being flagged as parser-inserted, set its force-async flag to false. Otherwise, set its force-async flag to true. (Note that createContextualFragment, innerHTML and XSLTProcessor::transformToFragment-created scripts are not flagged as parser-inserted.) This flag setting happens before any attributes (even parser-set ones) are set on the node.&lt;br /&gt;
&lt;br /&gt;
When a previously-created script element node loses its parser-insertedness, if the element doesn&#039;t have the async content attribute, set the force-async flag to true and false otherwise.&lt;br /&gt;
&lt;br /&gt;
When a script element node obtains the async content attribute (via setAttribute, setAttributeNode, setAttributeNS, by the fragment parser or the XSLTProcessor adding the attribute, etc.), set the force-async flag to false. (Note that calling removeAttribute(&amp;quot;async&amp;quot;) doesn&#039;t modify the force-async flag.)&lt;br /&gt;
&lt;br /&gt;
The async IDL attribute must behave as follows:&lt;br /&gt;
* Upon setting, set the force-async flag to false and then reflect the async content attribute.&lt;br /&gt;
* Upon getting, if the force-async flag is true, return true. Otherwise, reflect the async content attribute.&lt;br /&gt;
&lt;br /&gt;
In step 13. of http://www.whatwg.org/specs/web-apps/current-work/#running-a-script before the case &amp;quot;If the element has a src attribute&amp;quot; add a case:&lt;br /&gt;
If the script has a src attribute and the async IDL property getter returns false,&lt;br /&gt;
The element must be added to the queue of ordered script-inserted external scripts of the Document of the script element at the time the running a script algorithm started.&lt;br /&gt;
&lt;br /&gt;
The task that the networking task source places on the task queue once the fetching algorithm has completed must run these steps:&lt;br /&gt;
# If the queue of ordered script-inserted external scripts is empty or the first script in the queue of ordered script-inserted external scripts has not been fetched yet, abort these steps.&lt;br /&gt;
# Execute the first script in the queue of ordered script-inserted external scripts.&lt;br /&gt;
# Remove the first script from queue of ordered script-inserted external scripts.&lt;br /&gt;
# Goto step #1.&lt;br /&gt;
&lt;br /&gt;
Modify step 5 of  http://www.whatwg.org/specs/web-apps/current-work/#the-end to say:&lt;br /&gt;
Spin the event loop until the set of scripts that will execute as soon as possible is empty and the queue of ordered script-inserted external scripts is empty.&lt;br /&gt;
&lt;br /&gt;
==== Limitations ==== &lt;br /&gt;
The two behaviors being identified solve either the case where no dependencies exist, or where a linear dependency chain exists (and which the script elements can be requested to execute in that order). It is possible that some authors have a more complex non-linear dependency chain that they would like to express. This would obviously require a much more complex API and spec change, and since that use-case has not (yet) surfaced as a particularly main-stream request, I believe it would be overengineering to try to address it with this proposed change set.&lt;br /&gt;
&lt;br /&gt;
In addition, it&#039;s been duly noted that it&#039;s undesirable (and potentially confusing/problematic) to intentionally build in the inconsistency of having the &amp;quot;async&amp;quot; attribute (for parser-inserted scripts) and the &amp;quot;async&amp;quot; property (for script-inserted scripts) have different default values (&amp;quot;false&amp;quot; for the attribute, &amp;quot;true&amp;quot; for the property).&lt;br /&gt;
&lt;br /&gt;
It&#039;s also been a point of discussion whether or not such a spec change has enough &amp;quot;carrot&amp;quot; to entice the browser vendors (namely IE and Webkit) to implement the behavior. Moreover, there&#039;s been some concern that if the default value for the &amp;quot;async&amp;quot; property were made to be &amp;quot;false&amp;quot; (like the attribute) to be more consistent and conservative, then it would possibly give the perception to IE and Webkit of &amp;quot;losing&amp;quot; some performance to cut out their default &amp;quot;as fast as possible&amp;quot; behavior.&lt;br /&gt;
&lt;br /&gt;
=== Alternate Proposals === &lt;br /&gt;
One early proposal on the email list was to introduce an entirely new property like &amp;quot;ordered&amp;quot; which an author could add to a script-inserted script element to instruct the browser to put it into the queue of execution-order-preserving script loadings. While such a property would address the use case, it introduces another property and thus more complicates the issue. It also fails to address the current spec inconsistency (which is confusing to new comers) that &amp;quot;async&amp;quot; is not a present/respected property in mirror of the attribute of the same name.&lt;br /&gt;
&lt;br /&gt;
Another suggestion was a &amp;quot;waitFor&amp;quot; property that would be added to script elements and would specify a list of one or more DOM id&#039;s of other script elements that the current script should &amp;quot;wait for&amp;quot; in terms of execution. Again, this would solve the use case, but in a more complicated way, and there are concerns that it would be too confusing for the normal use-case.&lt;br /&gt;
&lt;br /&gt;
Several suggestions have come in the form of creating explicit &amp;quot;preloading&amp;quot; (similar to &amp;amp;lt;link rel=prefetch&amp;gt;), but as described above, &amp;quot;preloading&amp;quot; to solve this use case is a non-ideal hack and highly susceptible to breakage if the script fails to be sent with proper caching headers.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also been suggested that since this type of behavior is somewhat complicated, it may be better to intentionally obfuscate or complicate any such facility in the HTML, so as to make the barrier-to-entry rather high and force users to know what they are doing before doing it.&lt;br /&gt;
&lt;br /&gt;
It&#039;s been suggested that &amp;quot;defer&amp;quot; already preserves execution order. However, &amp;quot;defer&amp;quot; is only defined for parser-inserted scripts, and thus is not applicable to the use-case in question from an on-demand point of view. Also, &amp;quot;defer&amp;quot; scripts explicitly way for DOMContentLoaded, even if they&#039;re ready to execute sooner. So this is less than desired.&lt;br /&gt;
&lt;br /&gt;
Yet another proposal is a &amp;quot;document.executeScripts()&amp;quot; API, where an author can specify multiple sets of scripts that can load in parallel and it will enforce their execution order. A variation on that same idea was to use the &amp;quot;importScripts&amp;quot; from the Web Workers spec, however &amp;quot;importScripts&amp;quot; is synchronous (undesirable performance wise, obviously). The main downside (besides extra API complication) to &amp;quot;document.executeScripts()&amp;quot; is that there seem to be quite a few script execution properties/behaviors (including &amp;quot;document.currentScript&amp;quot; and charset override) which would have to be duplicated into this API facility.&lt;br /&gt;
&lt;br /&gt;
==== &amp;quot;Script Group&amp;quot; element ====&lt;br /&gt;
One recent alternate proposal bears some special consideration, as it seems like it might be a decent option (although certainly more of a radical change for the spec and for browsers to implement). But it has the appearance of being pretty straightforward and semantic for authors to use, perhaps even more so than using &amp;quot;async&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The proposal is to create a new HTML element, called perhaps &amp;amp;lt;scriptGroup&amp;gt;, &amp;amp;lt;collection&amp;gt;, etc. Specifically, this element must be able to be inserted wherever a &amp;amp;lt;script&amp;gt; element can currently be inserted. The &amp;quot;script group&amp;quot; element is intended to signify that all script elements added to it must perserve insertion execution order. This element wouldn&#039;t have much (but still some, explained in a moment) meaning in a parser-inserted context, since parser-inserted scripts already preserve order among themselves.&lt;br /&gt;
&lt;br /&gt;
An advantage of the &amp;quot;script group&amp;quot; element would be to give a direct and easy way to attach event listeners (&amp;quot;load&amp;quot; and &amp;quot;error&amp;quot;) to the entire group, rather than having to internally track events for each element if all you care about is the final &amp;quot;load&amp;quot; event, for instance. In the case of event handling, the &amp;quot;script group&amp;quot; element would have perhaps some benefit even in parser-inserted (markup) context.&lt;br /&gt;
&lt;br /&gt;
The element would need to have an &amp;quot;id&amp;quot; property, and possibly attributes for &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events.&lt;br /&gt;
&lt;br /&gt;
A variation on how to look at this proposal is that a &amp;quot;script group&amp;quot; element could have an attribute/property on it (perhaps called &amp;quot;ordered&amp;quot;) which would allow the group to either be order preserved or not. This would make the &amp;quot;script group&amp;quot; element much more useful in the parser-inserted context, as it would sort of be a shortcut to setting &amp;quot;async=true&amp;quot; on all the child script elements.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;script group&amp;quot; element might look like this:&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group1&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;foo.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;bar.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      somethingInline();&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, with the &amp;quot;ordered&amp;quot; attribute to explicitly control ordering behavior for the group:&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group1&amp;quot; ordered=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;foo.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;bar.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      somethingInline();&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group2&amp;quot; ordered=&amp;quot;false&amp;quot; onload=&amp;quot;alldone();&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;baz.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;far.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;zab.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the &amp;quot;script group&amp;quot; element is definitely more complicated to define and implement, it does have some semantic advantages for authors, and it also would significantly reduce the internal complexity of script loaders like LABjs. It would give authors (either directly or through script loaders) the flexibility to group scripts together into one of the two aforementioned behaviors (execution &amp;quot;as fast as possible&amp;quot; or &amp;quot;in insertion order&amp;quot;), and to easily access both behaviors in the same page.&lt;br /&gt;
&lt;br /&gt;
==== Explicit support for &amp;quot;text/cache&amp;quot; MIME type behavior ====&lt;br /&gt;
Yet another alternate proposal has been suggested in the [[Talk:Dynamic_Script_Execution_Order]] thread. &lt;br /&gt;
&lt;br /&gt;
Essentially, the proposal is that &amp;amp;lt;script&amp;gt; tags directly support being declared with a `type` value of &amp;quot;text/cache&amp;quot;. The behavior would be that the script resource is fetched, as the load events fired, as normal, but that the script itself would not be executed. Then later, at the desired time, the script in that element could be executed by changing the `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The browser would probably need to keep track (via some internal flag) that the script node is only ever executed once. Also, it&#039;s an open question if such a &amp;quot;cached&amp;quot; script node should be able to have its script content modified before execution via the `text` property.&lt;br /&gt;
&lt;br /&gt;
==== readyState &amp;quot;preloading&amp;quot; ====&lt;br /&gt;
Per the suggestion/comment added to the above [[Dynamic_Script_Execution_Order#Current_Limitations|Current Limitations]] section, it&#039;s been suggested that IE&#039;s current behavior with respect to the `readyState` property can adequately serve the use-case in question. This alternate proposal is very similar in spirit to the [[Dynamic_Script_Execution_Order#Explicit_support_for_.22text.2Fcache.22_MIME_type_behavior|previous section on explicit support for &amp;quot;text/cache&amp;quot;]] mime-type value.&lt;br /&gt;
&lt;br /&gt;
The idea is that IE will begin fetching into the cache a script resource as soon as the `src` attribute of the dynamic script element is set. But IE will not execute the script (even if it finishes loading) until the script element is added to the DOM. However, the `readyState` property of the element, combined with the `onreadystatechange` handler listening for changes, can detect when the script has finished loading, by receiving the &amp;quot;loaded&amp;quot; value.&lt;br /&gt;
&lt;br /&gt;
In this way, a script loader could &amp;quot;preload&amp;quot; a set of scripts all in parallel, but control their execution order by delaying the appending of the element to the DOM until execution is desired.&lt;br /&gt;
&lt;br /&gt;
[[Category:Feature Request|Dynamic Script Execution Order]]&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Dynamic_Script_Execution_Order&amp;diff=5617</id>
		<title>Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Dynamic_Script_Execution_Order&amp;diff=5617"/>
		<updated>2010-12-15T18:21:52Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* Current Limitations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is intended to formalize the discussion around an important but currently underserved use-case (in both spec and various browser implementations): the need for a dynamic script loading facility that can download resources in parallel but ensure that they execute serially in insertion order, for dependency reasons.&lt;br /&gt;
&lt;br /&gt;
A long email thread on the W3C public-html list, which began [http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html here] and for which a recent message is [http://lists.w3.org/Archives/Public/public-html/2010Oct/0415.html here], has been discussing this problem, but the email thread is becoming unruly and hard to track, so this wiki page will now be the official location to discuss the topic.&lt;br /&gt;
&lt;br /&gt;
Briefly, this issue has arisen because recent &amp;quot;nightlies&amp;quot; changes in both Mozilla Gecko and Webkit have broken the ability for script-loaders like [http://labjs.com LABjs] to be able to download scripts in parallel but ensure their execution order. As a result of the discussion, it&#039;s become apparent that both the spec for, and various current browser implementations around, dynamic script loading is incomplete in addressing this use case, and that some change needs to occur.&lt;br /&gt;
&lt;br /&gt;
There is one main proposal that has surfaced from the discussions, with several other alternatives having been discussed. This page will try to distill the long email thread down and clearly present the main proposal, objections, and alternative suggestions.&lt;br /&gt;
&lt;br /&gt;
Please feel free to join the discussion of this topic in the [[Talk:Dynamic_Script_Execution_Order]] area.&lt;br /&gt;
&lt;br /&gt;
== Use Case Description ==&lt;br /&gt;
Script tags/elements can either: &lt;br /&gt;
&lt;br /&gt;
a) appear in the HTML markup (&amp;quot;parser-inserted&amp;quot;), OR&lt;br /&gt;
&lt;br /&gt;
b) be dynamically appended to the DOM using document.createElement() (&amp;quot;script-inserted&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Parser-inserted script tags, up until recent browser versions, had the undesirable performance behavior of loading and executing serially, blocking everything else while doing so. Recently, many browsers have improved the situation by loading the scripts in parallel, but still executing them in order.&lt;br /&gt;
&lt;br /&gt;
On-demand (or dynamic) script loading has emerged in recent years for a variety of different reasons, most notably the performance improvements to address such concerns. It is desired by many different scenarios to be able to download scripts to a page completely independently of the loading of the rest of a page&#039;s resources, or even well after a page has finished loading (&amp;quot;on-demand&amp;quot;).  &lt;br /&gt;
&lt;br /&gt;
Recent additions to HTML spec such as &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; were intended to address the use-case for parser-inserted script elements, but their behaviors have been unhelpful for the on-demand loading use-case (script-inserted script elements).&lt;br /&gt;
&lt;br /&gt;
Thus, script loaders (like [http://labjs.com LABjs]) were developed to give page authors an easy way to specify one or more scripts to load (regardless of when in the life-time of the page that loading is requested), and for as many of them as possible to load in parallel, and for those scripts to be loadable from any local or remote domain location, and for the script loader to be able to control the execution order (if the usage of the script loader&#039;s API expresses the need to) to preserve dependencies between the scripts.&lt;br /&gt;
&lt;br /&gt;
Sometimes, dynamic script loading is used to load totally independent scripts, and thus &amp;quot;as fast as possible&amp;quot; execution is desired. Other times (and possibly more frequently), multiple scripts are loaded with some  dependencies among them, requiring them to execute in a certain order. &lt;br /&gt;
&lt;br /&gt;
What is needed is some facility by which a script loader can express that dynamic script loading either does or does not need execution order preserved among the queue of requested script loadings.&lt;br /&gt;
&lt;br /&gt;
=== Current Limitations ===&lt;br /&gt;
Unfortunately, browser behavior around script-inserted script elements and their loading and execution behavior is splintered. There are, at present, two main camps of behavior:&lt;br /&gt;
&lt;br /&gt;
a) in IE and Webkit (including Chrome), the default behavior for script-inserted script elements is for them all to execute in &amp;quot;as fast as possible&amp;quot; mode, meaning there&#039;s no guarantee about ordering. This effectively makes on-demand (dynamic) script loading impossible to work in parallel-mode if the resources in question have dependencies -- the only straight-forward way to handle things is to load each file and execute, serially, losing the parallel loading performance benefits.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
I&#039;m not sure if this is the case.  &lt;br /&gt;
&lt;br /&gt;
IE will start fetching resources without execution simply by setting the src attribute.  Scripts will not execute, however, until they are added to the document.  Since IE supports the readyState attribute and readystatechange event, it&#039;s possible to load scripts in parallel and execute them in order without resorting to invalid type attribute hack-ery.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:white&amp;quot; lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
script= document.createElement(&amp;quot;SCRIPT&amp;quot;); &lt;br /&gt;
script.onreadystatechange= function(){ &lt;br /&gt;
    if(this.readyState == &#039;loaded&#039;)&lt;br /&gt;
          /* &lt;br /&gt;
             Network fetch is now complete, following&lt;br /&gt;
             triggers synchronous execution.  &lt;br /&gt;
          */&lt;br /&gt;
          document.body.appendChild(this); &lt;br /&gt;
    else if(this.readyState == &amp;quot;complete&amp;quot;)&lt;br /&gt;
          this.onreadystatechange= null; &lt;br /&gt;
}&lt;br /&gt;
script.src= &amp;quot;foo.js&amp;quot;; &lt;br /&gt;
/* Network fetching begins now */&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #ccc&amp;quot;&amp;gt;&lt;br /&gt;
I&#039;ve experimented with such things heavily in the past, and I&#039;m fairly suspicious that this is not reliable across various versions of IE (6-9), nor does it work reliably the same depending on if an element is already in the browser cache or not. I&#039;m not 100% certain that what you suggest is flawed, but I have a strong hunch that it can be shown to have some holes in it for IE loading. I will try to create some test cases to prove or disprove.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
When loading a script that is in the cache, IE requires the event handler be installed prior to setting the `src` attribute.  Otherwise the element&#039;s transition to the &amp;quot;loaded&amp;quot; state will be missed.  IE routinely &amp;quot;skips&amp;quot; ready state transitions when cached scripts are immediately inserted into the DOM so suspicion is understandable; however, delayed insertion works around this &amp;quot;problem&amp;quot;.  The script above has been tested in IE6-8 with scripts in a variety of caching states and found to work correctly. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Moreover, you&#039;re suggesting something that is AFAIK only IE right now, and definitely appears to not be standardized. In the same way that I&#039;m hesitant to continue pinning loading behavior on hacks like the invalid type attribute value, I wouldn&#039;t want to approach loading with this technique (even if it were proven reliable on all IE&#039;s under all caching circumstances) unless it was a serious proposal to the W3C to have this technique be the new standard (as opposed to the current proposal, as implemented by Mozilla and Webkit now).&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
I think you&#039;re right: Only IE impelements this event and property on script elements.  The readystatechange event, however, is widely understood due to the XmlHttpRequest implementation and `readyState` property has been added to the `document` in WebKit, Mozilla and IE. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
That having been said, I think this is at least a viable candidate for &amp;quot;Alternate Proposals&amp;quot; and deserves to be listed as such. As always, I welcome input from the community on all the ideas presented here, including this one. But, since the main proposal (async=false) is already being implemented by at least two major browsers, I&#039;m not sure if the tide will be changed or not.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
b) in Gecko and Opera, the default behavior for script-inserted script elements is for them all to load in parallel, but execute serially in insertion order. Technically, this makes it impossible to dynamically load independent script elements and have them execute in &amp;quot;as fast as possible&amp;quot; mode.&lt;br /&gt;
&lt;br /&gt;
As described above, both behaviors are desirable under different circumstances, but each of the two camps provides only one behavior, and no way to straightforwardly achieve the other. This obviously creates a big nightmare interoperability-wise when trying to provide a general script loader cross-browser.&lt;br /&gt;
&lt;br /&gt;
Since it is observed that the behavior in (a) is more detrimental (race-condition wise) for the case where dependencies exist, script loaders like LABjs had to find some way around this problem while still attempting the best possible parallel loading performance. However, the trick used is hacky and not completely reliable -- yet it is the best way to solve the use-case in &amp;lt;s&amp;gt;IE and &amp;lt;/s&amp;gt;Webkit. &lt;br /&gt;
&lt;br /&gt;
For Gecko/Opera, the concession was just (silently) made that the lesser-common use case of &amp;quot;as fast as possible&amp;quot; wasn&#039;t possible, but degraded fine to &amp;quot;insertion order execution&amp;quot;, while keeping the parallel loading benefits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
Gecko&#039;s strict execution order creates dependencies between scripts which are unrelated and prevents the ability mitigate the impact of server outages / network latency.  This is exacerbated by the fact that Gecko, unlike IE and WebKit, provides no mechanism to &amp;lt;b&amp;gt;remove&amp;lt;/b&amp;gt; scripts from the execution queue. &lt;br /&gt;
&lt;br /&gt;
Consider the case where JSONP is used to provide auto-completion.  The user types &amp;quot;hello&amp;quot; and the JSONP request is made; however, the &amp;quot;currently&amp;quot; loading script is out-of-date as soon as the user modifies his search to &amp;quot;hello world&amp;quot;.  Gecko&#039;s algorithm requires the out-of-date request load and execute before the second request.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Recently, Gecko landed a [http://hg.mozilla.org/mozilla-central/rev/a60414d076b5 patch] to the trunk that stopped Gecko&#039;s existing behavior of preserving execution order, making script-inserted script elements now execute in &amp;quot;as fast as possible&amp;quot; mode similiar to IE/Webkit. Unfortunately, the &amp;quot;workaround&amp;quot; used in IE/Webkit (described in the next section) for dealing with parallel loading and execution-order dependencies does not work in Gecko, which means presently the use-case in question is now broken in Gecko trunk/FF4 nightlies.&lt;br /&gt;
&lt;br /&gt;
Moreover, Webkit recently landed a [http://trac.webkit.org/changeset/67245 patch] to the trunk that stopped Webkit&#039;s non-standard but long-held behavior (also used in the &amp;quot;workaround&amp;quot; described in the next section) of loading into cache script resources with an unrecognized &amp;quot;type&amp;quot; value, but silently not executing them. This behvaior (while hacky) is central to being able to address the use-case in question in Webkit, so at present, Webkit nightlies are now also entirely broken on the use-case (though in a different way than Gecko).&lt;br /&gt;
&lt;br /&gt;
Both the Gecko change and the Webkit change are well-intentioned, as they are bringing the respective browser more in line with the HTML spec. However, what&#039;s really been demonstrated is that the HTML spec is not properly handling this use-case, and so the goal is not to address the browser issues raised with more awkward hacks, but to address the shortcomings of the spec first, and then encourage all browsers to adhere to such.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
Considering Internet Explorer&#039;s readyState implementation provides a means of both parallel loading and preserving execution order can be achieved, perhaps its &amp;quot;readyState&amp;quot; property and onreadystatechange event should be included. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Current Usage and Workarounds ===&lt;br /&gt;
To work around the limitation in IE/Webkit(prior to the above noted patch) of not being able to rely on script order execution for parallel loaded scripts, a &amp;quot;preloading&amp;quot; trick was developed. This trick relied on non-standard (but long-held) behavior in these browsers that a script-inserted script element with an unrecognized &amp;quot;type&amp;quot; value (such as &amp;quot;script/cache&amp;quot;) would be fetched/loaded, but would not execute. This had the effect of loading the resource into cache, and then firing the &amp;quot;load&amp;quot; handlers to let the page know when the resource was completely in cache. &lt;br /&gt;
&lt;br /&gt;
Assuming that the resource was served with proper caching headers, and was in fact in the cache, it could then be executed (nearly) immediately when it was the proper execution order time by re-requesting the same resource via another script-inserted script element with the proper &amp;quot;text/javascript&amp;quot; type value, pulling the resource from the cache and executing it, without another server round-trip.&lt;br /&gt;
&lt;br /&gt;
Of course, the assumption of proper cache headers is a huge one, and not at all reliable. Some recent estimates by performance optimization specialists have suggested as much as 70% of scripts across the internet are not served with proper caching headers, which means that such scripts would be completely ineffective if loaded using this (or a similar) technique. The script resource would end up being loaded completely a second-time, and the &amp;quot;near immediate&amp;quot; execution would obviously be false, and thus race conditions would ensue.&lt;br /&gt;
&lt;br /&gt;
It&#039;s important to note at this point that the new &amp;amp;lt;link rel=prefetch&amp;gt; facility has been suggested as a better workaround, but it suffers the same ill-fated assumption of script cacheability. Still others have suggested &amp;quot;new Image().src=...&amp;quot; or the [http://www.phpied.com/preload-then-execute/ &amp;amp;lt;object&amp;amp;gt; preloading trick] suggested by Stoyan Stefanov. Again, these tricks unwisely assume cacheability, for the &amp;quot;preloading&amp;quot; trick to solve the use-case in question.&lt;br /&gt;
&lt;br /&gt;
=== At Risk ===&lt;br /&gt;
Currently, there are several large/popular web sites which are either currently (or who intend to soon) use LABjs in such a way as to run afoul of the new Gecko and Webkit behavioral changes with LABjs failing to operate properly. It&#039;s important to note that the problems of race conditions can be subtle and hard to detect, and so merely loading up such sites and failing to observe overt failure is not sufficient.&lt;br /&gt;
&lt;br /&gt;
Sites which are known to have LABjs loading techniques in place with currently broken (or susceptible to such breakage in the near future) behavior are:&lt;br /&gt;
&lt;br /&gt;
* [http://twitter.com Twitter]&lt;br /&gt;
* [http://zappos.com Zappos]&lt;br /&gt;
* [http://vimeo.com Vimeo]&lt;br /&gt;
* [http://mefeedia.com MeFeedia]&lt;br /&gt;
* [http://blog.getify.com Getify Solutions blog (my blog)]&lt;br /&gt;
* [http://flensed.com flensed Flash+JavaScript browser shims (cross-domain Ajax, cross-browser cookies, etc)]&lt;br /&gt;
&lt;br /&gt;
Rather than getting hung up in the syntax of usage in LABjs that is or is not going to break, it&#039;s best to just think of the problem this way:&lt;br /&gt;
&lt;br /&gt;
Does a site need to load more than one script, at least one of which comes from a remote domain location (like a CDN), and for which among the scripts there&#039;s at least one execution-order dependency among them? If so, then that site is susceptible to the current/future breakage if the HTML spec (and browsers) do not address this use case.&lt;br /&gt;
&lt;br /&gt;
A common example (in use on many sites) of such might be loading:&lt;br /&gt;
&lt;br /&gt;
* jQuery from the CDN&lt;br /&gt;
* jQuery-UI from the CDN&lt;br /&gt;
* plugins and usage code in one or more local files&lt;br /&gt;
* Google Analytics from the Google domain&lt;br /&gt;
&lt;br /&gt;
Note that the emergence of popular script frameworks and their hosting on public CDN&#039;s is leading to more and more sites loading scripts from both local and remote locations, and also to loading more files that have dependencies (rather than the practice of concat&#039;ing all files into one file to avoid dependency issues).&lt;br /&gt;
&lt;br /&gt;
Any site which fits a profile like the above, and which might currently (many do), or in the future want to, use a script loader to improve their loading performance, will fail to achieve what they want cross-browser and in a performant way, if the HTML spec (and browsers) do not address the use case.&lt;br /&gt;
&lt;br /&gt;
=== Benefits ===&lt;br /&gt;
The benefits of addressing both behaviors directly (without &amp;quot;preloading&amp;quot; tricks and bad assumption reliance) have been implied in the above discussion, but in short are:&lt;br /&gt;
&lt;br /&gt;
a) clear and simplified code for script loaders, which leads to easier use by authors of more pages, which in turn leads to better web performance (as demonstrated clearly by intelligent script loading techniques as compared to just simple &amp;amp;lt;script&amp;gt; tags in HTML markup)&lt;br /&gt;
&lt;br /&gt;
b) full access to either/both of the execution-order behaviors (as the author sees fit), regardless of browser&lt;br /&gt;
&lt;br /&gt;
c) avoiding reliance on bad assumptions (like cacheability) as a sufficient way to address the use-case&lt;br /&gt;
&lt;br /&gt;
=== External Discussions of this Feature ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html W3C public-html email thread]&amp;lt;/cite&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://www.w3.org/Bugs/Public/show_bug.cgi?id=11295 W3C Bug #11295]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[https://bugzilla.mozilla.org/show_bug.cgi?id=602838 Mozilla Bug #602838]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[https://bugs.webkit.org/show_bug.cgi?id=50115 Webkit Bug #50115]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://hsivonen.iki.fi/script-execution/ HTML5 Script Execution Changes in Firefox 4 Beta 7]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://blog.getify.com/2010/10/labjs-w3c-brief-update/ LABjs and W3C... brief update]&amp;lt;/cite&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://blog.getify.com/2010/10/ff4-script-loaders-and-order-preservation/ FF4, script loaders, and order preservation]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proposed Solutions ==&lt;br /&gt;
&lt;br /&gt;
=== My Solution ===&lt;br /&gt;
The current proposal most well supported from the email discussion thread, and the one which I feel makes most sense, is described here.&lt;br /&gt;
&lt;br /&gt;
The HTML spec already defines the &amp;quot;async&amp;quot; attribute for parser-inserted script tags, which when set to &amp;quot;true&amp;quot;, changes their execution order behavior to be like script-inserted script-elements (in IE/Webkit), which is that they load in parallel and execute &amp;quot;as fast as possible&amp;quot; (ostensibly because the author is expressing no dependencies between multiple such &amp;quot;async&amp;quot;-marked scripts). Parser-inserted script elements without &amp;quot;async&amp;quot; (or with it set to false) behave as before and expected, which is that they load in parallel but execute in order.&lt;br /&gt;
&lt;br /&gt;
However, the HTML spec does not define the &amp;quot;async&amp;quot; property (or any such behavior) for script-inserted script nodes (such as those created by a script loader). Instead, the spec implies that &amp;quot;async=true&amp;quot; like behavior is always true for such script-inserted script elements.&lt;br /&gt;
&lt;br /&gt;
What is proposed is:&lt;br /&gt;
&lt;br /&gt;
a) Script-inserted script elements should have (and respect the value of) an &amp;quot;async&amp;quot; property which is basically identical to the &amp;quot;async&amp;quot; attribute for parser-inserted script elements. That is, script elements with the &amp;quot;async&amp;quot; property set to &amp;quot;true&amp;quot; will behave accordingly, as will script elements with the &amp;quot;async&amp;quot; property set to false. &lt;br /&gt;
&lt;br /&gt;
Essentially, the proposal is to mirror the &amp;quot;async&amp;quot; attribute behavior of parser-inserted script elements as an &amp;quot;async&amp;quot; property on script-inserted script elements. This has the benefit of using an existing facility and extending it (from current spec) in a way that is sensisble and symmetric with its current definition.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EFEFEF&amp;quot;&amp;gt;&lt;br /&gt;
The scriptgroup or `readyState`  alternate proposals allow for dependency management to be done in high-level code.  The singular syncrhonized execution queue proposed here introduces artificial dependencies, undermining some of the benefits dynamic script loading provides.  &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #ccc;&amp;quot;&amp;gt;&lt;br /&gt;
It&#039;s important to note that `async=false` scripts will load in a separate queue from `async=true` scripts. It&#039;s not that all scripts will now be forced into this insertion-order-execution queue. An author (or script loader) can chose which queue to put a script loading into based on the needs of the page and the resource. If I have a few scripts that are unrelated to each other and the main page (like Google Analytics, social sharing buttons, etc), I&#039;ll load those via `async=true`. For other scripts, where order matters for dependency sake, I&#039;ll use `async=false`. I think having both those queues available to high-level code is enough control over loading to serve the majority of use-cases pretty well.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
b) Furthermore, to aid in &amp;quot;feature-detection&amp;quot; of such new behavior, the proposal is to have the default value for the &amp;quot;async&amp;quot; property of script-inserted script elements be &amp;quot;true&amp;quot; (and of course the associated behavior thereof).&lt;br /&gt;
&lt;br /&gt;
There are two major benefits to (b). One is that it provides a way to feature test such new behavior by not just looking for the existence of the &amp;quot;async&amp;quot; property on script elements, but specifically that the default value is &amp;quot;true&amp;quot; (which is opposite of what it would currently/normally be). Secondly, defaulting to &amp;quot;async=true&amp;quot; behavior for script-inserted script elements would preserve the default behavior of IE and Webkit, meaning there&#039;d be less of a chance of breaking existing web content in either of those two browsers.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also important to note that there is no implied or requested effect or dependency between script-inserted script elements and parser-inserted script elements -- the two types of scripts would load and execute in entirely separate behavioral sandboxes.&lt;br /&gt;
&lt;br /&gt;
==== Proposal Amendment: Events ====&lt;br /&gt;
In addition to standardizing how scripts load and execute, it&#039;s also important to standardize the load and error events, and under what circumstances they fire, etc. Without reliable load/error events, the main proposal is not reliable and is thus unhelpful for the use-case.&lt;br /&gt;
&lt;br /&gt;
A script-inserted script element must fire the &amp;quot;load&amp;quot; event only once, when:&lt;br /&gt;
&lt;br /&gt;
a) immediately after the resource finishes loading, but before parsing/execution, AND&lt;br /&gt;
&lt;br /&gt;
b) the script element loads any non-empty content (that is, it was a successful HTTP request), AND&lt;br /&gt;
&lt;br /&gt;
c) the script element has either loaded from the remote location, or is loaded from the brower cache&lt;br /&gt;
&lt;br /&gt;
Specifically, the script &amp;quot;load&amp;quot; event must come immediately between the script element finishing loading and the script element being parsed/executed. If the script resource successfully loads, nothing should interrupt the sequence of fininshing loading, the &amp;quot;load&amp;quot; event firing, and the script being parsed/executed.&lt;br /&gt;
&lt;br /&gt;
A script-inserted script element must fire the &amp;quot;error&amp;quot; event only once, when:&lt;br /&gt;
&lt;br /&gt;
a) immediately after a loading failure for the resource is detected (that is, an HTTP error received, such as 404, 500, 503, etc).&lt;br /&gt;
&lt;br /&gt;
Either the &amp;quot;load&amp;quot; or &amp;quot;error&amp;quot; event, but not both, will fire, and only once, for every script-inserted script element.&lt;br /&gt;
&lt;br /&gt;
NOTE: &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events on script-inserted script elements must fire synchronously to ensure event reliability.&lt;br /&gt;
&lt;br /&gt;
A case may be made for adding the &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events as described here to parser-inserted script elements as well.&lt;br /&gt;
&lt;br /&gt;
==== Processing Model ====&lt;br /&gt;
Script inserted script elements will have an &amp;quot;async&amp;quot; property that defaults to &amp;quot;true&amp;quot;. If the author does not change the value, all such requested script loadings will be in their own &amp;quot;queue&amp;quot; and will default to &amp;quot;as fast as possible&amp;quot; execution behavior. For any script elements that the author sets &amp;quot;async=false&amp;quot;, those scripts will load in a separate &amp;quot;queue&amp;quot;, and will execute in insertion order only. Again, these two &amp;quot;queues&amp;quot; will operate strictly independent of each other.&lt;br /&gt;
&lt;br /&gt;
==== Processing Model Details (without the event amendment) ====&lt;br /&gt;
&lt;br /&gt;
When a script element node is created, if it is being flagged as parser-inserted, set its force-async flag to false. Otherwise, set its force-async flag to true. (Note that createContextualFragment, innerHTML and XSLTProcessor::transformToFragment-created scripts are not flagged as parser-inserted.) This flag setting happens before any attributes (even parser-set ones) are set on the node.&lt;br /&gt;
&lt;br /&gt;
When a previously-created script element node loses its parser-insertedness, if the element doesn&#039;t have the async content attribute, set the force-async flag to true and false otherwise.&lt;br /&gt;
&lt;br /&gt;
When a script element node obtains the async content attribute (via setAttribute, setAttributeNode, setAttributeNS, by the fragment parser or the XSLTProcessor adding the attribute, etc.), set the force-async flag to false. (Note that calling removeAttribute(&amp;quot;async&amp;quot;) doesn&#039;t modify the force-async flag.)&lt;br /&gt;
&lt;br /&gt;
The async IDL attribute must behave as follows:&lt;br /&gt;
* Upon setting, set the force-async flag to false and then reflect the async content attribute.&lt;br /&gt;
* Upon getting, if the force-async flag is true, return true. Otherwise, reflect the async content attribute.&lt;br /&gt;
&lt;br /&gt;
In step 13. of http://www.whatwg.org/specs/web-apps/current-work/#running-a-script before the case &amp;quot;If the element has a src attribute&amp;quot; add a case:&lt;br /&gt;
If the script has a src attribute and the async IDL property getter returns false,&lt;br /&gt;
The element must be added to the queue of ordered script-inserted external scripts of the Document of the script element at the time the running a script algorithm started.&lt;br /&gt;
&lt;br /&gt;
The task that the networking task source places on the task queue once the fetching algorithm has completed must run these steps:&lt;br /&gt;
# If the queue of ordered script-inserted external scripts is empty or the first script in the queue of ordered script-inserted external scripts has not been fetched yet, abort these steps.&lt;br /&gt;
# Execute the first script in the queue of ordered script-inserted external scripts.&lt;br /&gt;
# Remove the first script from queue of ordered script-inserted external scripts.&lt;br /&gt;
# Goto step #1.&lt;br /&gt;
&lt;br /&gt;
Modify step 5 of  http://www.whatwg.org/specs/web-apps/current-work/#the-end to say:&lt;br /&gt;
Spin the event loop until the set of scripts that will execute as soon as possible is empty and the queue of ordered script-inserted external scripts is empty.&lt;br /&gt;
&lt;br /&gt;
==== Limitations ==== &lt;br /&gt;
The two behaviors being identified solve either the case where no dependencies exist, or where a linear dependency chain exists (and which the script elements can be requested to execute in that order). It is possible that some authors have a more complex non-linear dependency chain that they would like to express. This would obviously require a much more complex API and spec change, and since that use-case has not (yet) surfaced as a particularly main-stream request, I believe it would be overengineering to try to address it with this proposed change set.&lt;br /&gt;
&lt;br /&gt;
In addition, it&#039;s been duly noted that it&#039;s undesirable (and potentially confusing/problematic) to intentionally build in the inconsistency of having the &amp;quot;async&amp;quot; attribute (for parser-inserted scripts) and the &amp;quot;async&amp;quot; property (for script-inserted scripts) have different default values (&amp;quot;false&amp;quot; for the attribute, &amp;quot;true&amp;quot; for the property).&lt;br /&gt;
&lt;br /&gt;
It&#039;s also been a point of discussion whether or not such a spec change has enough &amp;quot;carrot&amp;quot; to entice the browser vendors (namely IE and Webkit) to implement the behavior. Moreover, there&#039;s been some concern that if the default value for the &amp;quot;async&amp;quot; property were made to be &amp;quot;false&amp;quot; (like the attribute) to be more consistent and conservative, then it would possibly give the perception to IE and Webkit of &amp;quot;losing&amp;quot; some performance to cut out their default &amp;quot;as fast as possible&amp;quot; behavior.&lt;br /&gt;
&lt;br /&gt;
=== Alternate Proposals === &lt;br /&gt;
One early proposal on the email list was to introduce an entirely new property like &amp;quot;ordered&amp;quot; which an author could add to a script-inserted script element to instruct the browser to put it into the queue of execution-order-preserving script loadings. While such a property would address the use case, it introduces another property and thus more complicates the issue. It also fails to address the current spec inconsistency (which is confusing to new comers) that &amp;quot;async&amp;quot; is not a present/respected property in mirror of the attribute of the same name.&lt;br /&gt;
&lt;br /&gt;
Another suggestion was a &amp;quot;waitFor&amp;quot; property that would be added to script elements and would specify a list of one or more DOM id&#039;s of other script elements that the current script should &amp;quot;wait for&amp;quot; in terms of execution. Again, this would solve the use case, but in a more complicated way, and there are concerns that it would be too confusing for the normal use-case.&lt;br /&gt;
&lt;br /&gt;
Several suggestions have come in the form of creating explicit &amp;quot;preloading&amp;quot; (similar to &amp;amp;lt;link rel=prefetch&amp;gt;), but as described above, &amp;quot;preloading&amp;quot; to solve this use case is a non-ideal hack and highly susceptible to breakage if the script fails to be sent with proper caching headers.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also been suggested that since this type of behavior is somewhat complicated, it may be better to intentionally obfuscate or complicate any such facility in the HTML, so as to make the barrier-to-entry rather high and force users to know what they are doing before doing it.&lt;br /&gt;
&lt;br /&gt;
It&#039;s been suggested that &amp;quot;defer&amp;quot; already preserves execution order. However, &amp;quot;defer&amp;quot; is only defined for parser-inserted scripts, and thus is not applicable to the use-case in question from an on-demand point of view. Also, &amp;quot;defer&amp;quot; scripts explicitly way for DOMContentLoaded, even if they&#039;re ready to execute sooner. So this is less than desired.&lt;br /&gt;
&lt;br /&gt;
Yet another proposal is a &amp;quot;document.executeScripts()&amp;quot; API, where an author can specify multiple sets of scripts that can load in parallel and it will enforce their execution order. A variation on that same idea was to use the &amp;quot;importScripts&amp;quot; from the Web Workers spec, however &amp;quot;importScripts&amp;quot; is synchronous (undesirable performance wise, obviously). The main downside (besides extra API complication) to &amp;quot;document.executeScripts()&amp;quot; is that there seem to be quite a few script execution properties/behaviors (including &amp;quot;document.currentScript&amp;quot; and charset override) which would have to be duplicated into this API facility.&lt;br /&gt;
&lt;br /&gt;
==== &amp;quot;Script Group&amp;quot; element ====&lt;br /&gt;
One recent alternate proposal bears some special consideration, as it seems like it might be a decent option (although certainly more of a radical change for the spec and for browsers to implement). But it has the appearance of being pretty straightforward and semantic for authors to use, perhaps even more so than using &amp;quot;async&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The proposal is to create a new HTML element, called perhaps &amp;amp;lt;scriptGroup&amp;gt;, &amp;amp;lt;collection&amp;gt;, etc. Specifically, this element must be able to be inserted wherever a &amp;amp;lt;script&amp;gt; element can currently be inserted. The &amp;quot;script group&amp;quot; element is intended to signify that all script elements added to it must perserve insertion execution order. This element wouldn&#039;t have much (but still some, explained in a moment) meaning in a parser-inserted context, since parser-inserted scripts already preserve order among themselves.&lt;br /&gt;
&lt;br /&gt;
An advantage of the &amp;quot;script group&amp;quot; element would be to give a direct and easy way to attach event listeners (&amp;quot;load&amp;quot; and &amp;quot;error&amp;quot;) to the entire group, rather than having to internally track events for each element if all you care about is the final &amp;quot;load&amp;quot; event, for instance. In the case of event handling, the &amp;quot;script group&amp;quot; element would have perhaps some benefit even in parser-inserted (markup) context.&lt;br /&gt;
&lt;br /&gt;
The element would need to have an &amp;quot;id&amp;quot; property, and possibly attributes for &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events.&lt;br /&gt;
&lt;br /&gt;
A variation on how to look at this proposal is that a &amp;quot;script group&amp;quot; element could have an attribute/property on it (perhaps called &amp;quot;ordered&amp;quot;) which would allow the group to either be order preserved or not. This would make the &amp;quot;script group&amp;quot; element much more useful in the parser-inserted context, as it would sort of be a shortcut to setting &amp;quot;async=true&amp;quot; on all the child script elements.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;script group&amp;quot; element might look like this:&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group1&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;foo.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;bar.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      somethingInline();&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, with the &amp;quot;ordered&amp;quot; attribute to explicitly control ordering behavior for the group:&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group1&amp;quot; ordered=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;foo.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;bar.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      somethingInline();&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group2&amp;quot; ordered=&amp;quot;false&amp;quot; onload=&amp;quot;alldone();&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;baz.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;far.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;zab.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the &amp;quot;script group&amp;quot; element is definitely more complicated to define and implement, it does have some semantic advantages for authors, and it also would significantly reduce the internal complexity of script loaders like LABjs. It would give authors (either directly or through script loaders) the flexibility to group scripts together into one of the two aforementioned behaviors (execution &amp;quot;as fast as possible&amp;quot; or &amp;quot;in insertion order&amp;quot;), and to easily access both behaviors in the same page.&lt;br /&gt;
&lt;br /&gt;
==== Explicit support for &amp;quot;text/cache&amp;quot; MIME type behavior ====&lt;br /&gt;
Yet another alternate proposal has been suggested in the [[Talk:Dynamic_Script_Execution_Order]] thread. &lt;br /&gt;
&lt;br /&gt;
Essentially, the proposal is that &amp;amp;lt;script&amp;gt; tags directly support being declared with a `type` value of &amp;quot;text/cache&amp;quot;. The behavior would be that the script resource is fetched, as the load events fired, as normal, but that the script itself would not be executed. Then later, at the desired time, the script in that element could be executed by changing the `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The browser would probably need to keep track (via some internal flag) that the script node is only ever executed once. Also, it&#039;s an open question if such a &amp;quot;cached&amp;quot; script node should be able to have its script content modified before execution via the `text` property.&lt;br /&gt;
&lt;br /&gt;
==== readyState &amp;quot;preloading&amp;quot; ====&lt;br /&gt;
Per the suggestion/comment added to the above [[Dynamic_Script_Execution_Order#Current_Limitations|Current Limitations]] section, it&#039;s been suggested that IE&#039;s current behavior with respect to the `readyState` property can adequately serve the use-case in question.&lt;br /&gt;
&lt;br /&gt;
The idea is that IE will begin fetching into the cache a script resource as soon as the `src` attribute of the dynamic script element is set. But IE will not execute the script (even if it finishes loading) until the script element is added to the DOM. However, the `readyState` property of the element, combined with the `onreadystatechange` handler listening for changes, can detect when the script has finished loading, by receiving the &amp;quot;loaded&amp;quot; value.&lt;br /&gt;
&lt;br /&gt;
In this way, a script loader could &amp;quot;preload&amp;quot; a set of scripts all in parallel, but control their execution order by delaying the appending of the element to the DOM until execution is desired.&lt;br /&gt;
&lt;br /&gt;
[[Category:Feature Request|Dynamic Script Execution Order]]&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Dynamic_Script_Execution_Order&amp;diff=5615</id>
		<title>Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Dynamic_Script_Execution_Order&amp;diff=5615"/>
		<updated>2010-12-15T17:57:32Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* My Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is intended to formalize the discussion around an important but currently underserved use-case (in both spec and various browser implementations): the need for a dynamic script loading facility that can download resources in parallel but ensure that they execute serially in insertion order, for dependency reasons.&lt;br /&gt;
&lt;br /&gt;
A long email thread on the W3C public-html list, which began [http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html here] and for which a recent message is [http://lists.w3.org/Archives/Public/public-html/2010Oct/0415.html here], has been discussing this problem, but the email thread is becoming unruly and hard to track, so this wiki page will now be the official location to discuss the topic.&lt;br /&gt;
&lt;br /&gt;
Briefly, this issue has arisen because recent &amp;quot;nightlies&amp;quot; changes in both Mozilla Gecko and Webkit have broken the ability for script-loaders like [http://labjs.com LABjs] to be able to download scripts in parallel but ensure their execution order. As a result of the discussion, it&#039;s become apparent that both the spec for, and various current browser implementations around, dynamic script loading is incomplete in addressing this use case, and that some change needs to occur.&lt;br /&gt;
&lt;br /&gt;
There is one main proposal that has surfaced from the discussions, with several other alternatives having been discussed. This page will try to distill the long email thread down and clearly present the main proposal, objections, and alternative suggestions.&lt;br /&gt;
&lt;br /&gt;
Please feel free to join the discussion of this topic in the [[Talk:Dynamic_Script_Execution_Order]] area.&lt;br /&gt;
&lt;br /&gt;
== Use Case Description ==&lt;br /&gt;
Script tags/elements can either: &lt;br /&gt;
&lt;br /&gt;
a) appear in the HTML markup (&amp;quot;parser-inserted&amp;quot;), OR&lt;br /&gt;
&lt;br /&gt;
b) be dynamically appended to the DOM using document.createElement() (&amp;quot;script-inserted&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Parser-inserted script tags, up until recent browser versions, had the undesirable performance behavior of loading and executing serially, blocking everything else while doing so. Recently, many browsers have improved the situation by loading the scripts in parallel, but still executing them in order.&lt;br /&gt;
&lt;br /&gt;
On-demand (or dynamic) script loading has emerged in recent years for a variety of different reasons, most notably the performance improvements to address such concerns. It is desired by many different scenarios to be able to download scripts to a page completely independently of the loading of the rest of a page&#039;s resources, or even well after a page has finished loading (&amp;quot;on-demand&amp;quot;).  &lt;br /&gt;
&lt;br /&gt;
Recent additions to HTML spec such as &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; were intended to address the use-case for parser-inserted script elements, but their behaviors have been unhelpful for the on-demand loading use-case (script-inserted script elements).&lt;br /&gt;
&lt;br /&gt;
Thus, script loaders (like [http://labjs.com LABjs]) were developed to give page authors an easy way to specify one or more scripts to load (regardless of when in the life-time of the page that loading is requested), and for as many of them as possible to load in parallel, and for those scripts to be loadable from any local or remote domain location, and for the script loader to be able to control the execution order (if the usage of the script loader&#039;s API expresses the need to) to preserve dependencies between the scripts.&lt;br /&gt;
&lt;br /&gt;
Sometimes, dynamic script loading is used to load totally independent scripts, and thus &amp;quot;as fast as possible&amp;quot; execution is desired. Other times (and possibly more frequently), multiple scripts are loaded with some  dependencies among them, requiring them to execute in a certain order. &lt;br /&gt;
&lt;br /&gt;
What is needed is some facility by which a script loader can express that dynamic script loading either does or does not need execution order preserved among the queue of requested script loadings.&lt;br /&gt;
&lt;br /&gt;
=== Current Limitations ===&lt;br /&gt;
Unfortunately, browser behavior around script-inserted script elements and their loading and execution behavior is splintered. There are, at present, two main camps of behavior:&lt;br /&gt;
&lt;br /&gt;
a) in IE and Webkit (including Chrome), the default behavior for script-inserted script elements is for them all to execute in &amp;quot;as fast as possible&amp;quot; mode, meaning there&#039;s no guarantee about ordering. This effectively makes on-demand (dynamic) script loading impossible to work in parallel-mode if the resources in question have dependencies -- the only straight-forward way to handle things is to load each file and execute, serially, losing the parallel loading performance benefits.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
I&#039;m not sure if this is the case.  &lt;br /&gt;
&lt;br /&gt;
IE will start fetching resources without execution simply by setting the src attribute.  Scripts will not execute, however, until they are added to the document.  Since IE supports the readyState attribute and readystatechange event, it&#039;s possible to load scripts in parallel and execute them in order without resorting to invalid type attribute hack-ery.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:white&amp;quot; lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
script= document.createElement(&amp;quot;SCRIPT&amp;quot;); &lt;br /&gt;
script.onreadystatechange= function(){ &lt;br /&gt;
    if(this.readyState == &#039;loaded&#039;)&lt;br /&gt;
          /* &lt;br /&gt;
             Network fetch is now complete, following&lt;br /&gt;
             triggers synchronous execution.  &lt;br /&gt;
          */&lt;br /&gt;
          document.body.appendChild(this); &lt;br /&gt;
    else if(this.readyState == &amp;quot;complete&amp;quot;)&lt;br /&gt;
          this.onreadystatechange= null; &lt;br /&gt;
}&lt;br /&gt;
script.src= &amp;quot;foo.js&amp;quot;; &lt;br /&gt;
/* Network fetching begins now */&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #ccc&amp;quot;&amp;gt;&lt;br /&gt;
I&#039;ve experimented with such things heavily in the past, and I&#039;m fairly suspicious that this is not reliable across various versions of IE (6-9), nor does it work reliably the same depending on if an element is already in the browser cache or not. I&#039;m not 100% certain that what you suggest is flawed, but I have a strong hunch that it can be shown to have some holes in it for IE loading. I will try to create some test cases to prove or disprove.&lt;br /&gt;
&lt;br /&gt;
Moreover, you&#039;re suggesting something that is AFAIK only IE right now, and definitely appears to not be standardized. In the same way that I&#039;m hesitant to continue pinning loading behavior on hacks like the invalid type attribute value, I wouldn&#039;t want to approach loading with this technique (even if it were proven reliable on all IE&#039;s under all caching circumstances) unless it was a serious proposal to the W3C to have this technique be the new standard (as opposed to the current proposal, as implemented by Mozilla and Webkit now).&lt;br /&gt;
&lt;br /&gt;
That having been said, I think this is at least a viable candidate for &amp;quot;Alternate Proposals&amp;quot; and deserves to be listed as such. As always, I welcome input from the community on all the ideas presented here, including this one. But, since the main proposal (async=false) is already being implemented by at least two major browsers, I&#039;m not sure if the tide will be changed or not.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
b) in Gecko and Opera, the default behavior for script-inserted script elements is for them all to load in parallel, but execute serially in insertion order. Technically, this makes it impossible to dynamically load independent script elements and have them execute in &amp;quot;as fast as possible&amp;quot; mode.&lt;br /&gt;
&lt;br /&gt;
As described above, both behaviors are desirable under different circumstances, but each of the two camps provides only one behavior, and no way to straightforwardly achieve the other. This obviously creates a big nightmare interoperability-wise when trying to provide a general script loader cross-browser.&lt;br /&gt;
&lt;br /&gt;
Since it is observed that the behavior in (a) is more detrimental (race-condition wise) for the case where dependencies exist, script loaders like LABjs had to find some way around this problem while still attempting the best possible parallel loading performance. However, the trick used is hacky and not completely reliable -- yet it is the best way to solve the use-case in &amp;lt;s&amp;gt;IE and &amp;lt;/s&amp;gt;Webkit. &lt;br /&gt;
&lt;br /&gt;
For Gecko/Opera, the concession was just (silently) made that the lesser-common use case of &amp;quot;as fast as possible&amp;quot; wasn&#039;t possible, but degraded fine to &amp;quot;insertion order execution&amp;quot;, while keeping the parallel loading benefits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
Gecko&#039;s strict execution order creates dependencies between scripts which are unrelated and prevents the ability mitigate the impact of server outages / network latency.  This is exacerbated by the fact that Gecko, unlike IE and WebKit, provides no mechanism to &amp;lt;b&amp;gt;remove&amp;lt;/b&amp;gt; scripts from the execution queue. &lt;br /&gt;
&lt;br /&gt;
Consider the case where JSONP is used to provide auto-completion.  The user types &amp;quot;hello&amp;quot; and the JSONP request is made; however, the &amp;quot;currently&amp;quot; loading script is out-of-date as soon as the user modifies his search to &amp;quot;hello world&amp;quot;.  Gecko&#039;s algorithm requires the out-of-date request load and execute before the second request.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Recently, Gecko landed a [http://hg.mozilla.org/mozilla-central/rev/a60414d076b5 patch] to the trunk that stopped Gecko&#039;s existing behavior of preserving execution order, making script-inserted script elements now execute in &amp;quot;as fast as possible&amp;quot; mode similiar to IE/Webkit. Unfortunately, the &amp;quot;workaround&amp;quot; used in IE/Webkit (described in the next section) for dealing with parallel loading and execution-order dependencies does not work in Gecko, which means presently the use-case in question is now broken in Gecko trunk/FF4 nightlies.&lt;br /&gt;
&lt;br /&gt;
Moreover, Webkit recently landed a [http://trac.webkit.org/changeset/67245 patch] to the trunk that stopped Webkit&#039;s non-standard but long-held behavior (also used in the &amp;quot;workaround&amp;quot; described in the next section) of loading into cache script resources with an unrecognized &amp;quot;type&amp;quot; value, but silently not executing them. This behvaior (while hacky) is central to being able to address the use-case in question in Webkit, so at present, Webkit nightlies are now also entirely broken on the use-case (though in a different way than Gecko).&lt;br /&gt;
&lt;br /&gt;
Both the Gecko change and the Webkit change are well-intentioned, as they are bringing the respective browser more in line with the HTML spec. However, what&#039;s really been demonstrated is that the HTML spec is not properly handling this use-case, and so the goal is not to address the browser issues raised with more awkward hacks, but to address the shortcomings of the spec first, and then encourage all browsers to adhere to such.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
Considering Internet Explorer&#039;s readyState implementation provides a means of both parallel loading and preserving execution order can be achieved, perhaps its &amp;quot;readyState&amp;quot; property and onreadystatechange event should be included. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Current Usage and Workarounds ===&lt;br /&gt;
To work around the limitation in IE/Webkit(prior to the above noted patch) of not being able to rely on script order execution for parallel loaded scripts, a &amp;quot;preloading&amp;quot; trick was developed. This trick relied on non-standard (but long-held) behavior in these browsers that a script-inserted script element with an unrecognized &amp;quot;type&amp;quot; value (such as &amp;quot;script/cache&amp;quot;) would be fetched/loaded, but would not execute. This had the effect of loading the resource into cache, and then firing the &amp;quot;load&amp;quot; handlers to let the page know when the resource was completely in cache. &lt;br /&gt;
&lt;br /&gt;
Assuming that the resource was served with proper caching headers, and was in fact in the cache, it could then be executed (nearly) immediately when it was the proper execution order time by re-requesting the same resource via another script-inserted script element with the proper &amp;quot;text/javascript&amp;quot; type value, pulling the resource from the cache and executing it, without another server round-trip.&lt;br /&gt;
&lt;br /&gt;
Of course, the assumption of proper cache headers is a huge one, and not at all reliable. Some recent estimates by performance optimization specialists have suggested as much as 70% of scripts across the internet are not served with proper caching headers, which means that such scripts would be completely ineffective if loaded using this (or a similar) technique. The script resource would end up being loaded completely a second-time, and the &amp;quot;near immediate&amp;quot; execution would obviously be false, and thus race conditions would ensue.&lt;br /&gt;
&lt;br /&gt;
It&#039;s important to note at this point that the new &amp;amp;lt;link rel=prefetch&amp;gt; facility has been suggested as a better workaround, but it suffers the same ill-fated assumption of script cacheability. Still others have suggested &amp;quot;new Image().src=...&amp;quot; or the [http://www.phpied.com/preload-then-execute/ &amp;amp;lt;object&amp;amp;gt; preloading trick] suggested by Stoyan Stefanov. Again, these tricks unwisely assume cacheability, for the &amp;quot;preloading&amp;quot; trick to solve the use-case in question.&lt;br /&gt;
&lt;br /&gt;
=== At Risk ===&lt;br /&gt;
Currently, there are several large/popular web sites which are either currently (or who intend to soon) use LABjs in such a way as to run afoul of the new Gecko and Webkit behavioral changes with LABjs failing to operate properly. It&#039;s important to note that the problems of race conditions can be subtle and hard to detect, and so merely loading up such sites and failing to observe overt failure is not sufficient.&lt;br /&gt;
&lt;br /&gt;
Sites which are known to have LABjs loading techniques in place with currently broken (or susceptible to such breakage in the near future) behavior are:&lt;br /&gt;
&lt;br /&gt;
* [http://twitter.com Twitter]&lt;br /&gt;
* [http://zappos.com Zappos]&lt;br /&gt;
* [http://vimeo.com Vimeo]&lt;br /&gt;
* [http://mefeedia.com MeFeedia]&lt;br /&gt;
* [http://blog.getify.com Getify Solutions blog (my blog)]&lt;br /&gt;
* [http://flensed.com flensed Flash+JavaScript browser shims (cross-domain Ajax, cross-browser cookies, etc)]&lt;br /&gt;
&lt;br /&gt;
Rather than getting hung up in the syntax of usage in LABjs that is or is not going to break, it&#039;s best to just think of the problem this way:&lt;br /&gt;
&lt;br /&gt;
Does a site need to load more than one script, at least one of which comes from a remote domain location (like a CDN), and for which among the scripts there&#039;s at least one execution-order dependency among them? If so, then that site is susceptible to the current/future breakage if the HTML spec (and browsers) do not address this use case.&lt;br /&gt;
&lt;br /&gt;
A common example (in use on many sites) of such might be loading:&lt;br /&gt;
&lt;br /&gt;
* jQuery from the CDN&lt;br /&gt;
* jQuery-UI from the CDN&lt;br /&gt;
* plugins and usage code in one or more local files&lt;br /&gt;
* Google Analytics from the Google domain&lt;br /&gt;
&lt;br /&gt;
Note that the emergence of popular script frameworks and their hosting on public CDN&#039;s is leading to more and more sites loading scripts from both local and remote locations, and also to loading more files that have dependencies (rather than the practice of concat&#039;ing all files into one file to avoid dependency issues).&lt;br /&gt;
&lt;br /&gt;
Any site which fits a profile like the above, and which might currently (many do), or in the future want to, use a script loader to improve their loading performance, will fail to achieve what they want cross-browser and in a performant way, if the HTML spec (and browsers) do not address the use case.&lt;br /&gt;
&lt;br /&gt;
=== Benefits ===&lt;br /&gt;
The benefits of addressing both behaviors directly (without &amp;quot;preloading&amp;quot; tricks and bad assumption reliance) have been implied in the above discussion, but in short are:&lt;br /&gt;
&lt;br /&gt;
a) clear and simplified code for script loaders, which leads to easier use by authors of more pages, which in turn leads to better web performance (as demonstrated clearly by intelligent script loading techniques as compared to just simple &amp;amp;lt;script&amp;gt; tags in HTML markup)&lt;br /&gt;
&lt;br /&gt;
b) full access to either/both of the execution-order behaviors (as the author sees fit), regardless of browser&lt;br /&gt;
&lt;br /&gt;
c) avoiding reliance on bad assumptions (like cacheability) as a sufficient way to address the use-case&lt;br /&gt;
&lt;br /&gt;
=== External Discussions of this Feature ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html W3C public-html email thread]&amp;lt;/cite&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://www.w3.org/Bugs/Public/show_bug.cgi?id=11295 W3C Bug #11295]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[https://bugzilla.mozilla.org/show_bug.cgi?id=602838 Mozilla Bug #602838]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[https://bugs.webkit.org/show_bug.cgi?id=50115 Webkit Bug #50115]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://hsivonen.iki.fi/script-execution/ HTML5 Script Execution Changes in Firefox 4 Beta 7]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://blog.getify.com/2010/10/labjs-w3c-brief-update/ LABjs and W3C... brief update]&amp;lt;/cite&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://blog.getify.com/2010/10/ff4-script-loaders-and-order-preservation/ FF4, script loaders, and order preservation]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proposed Solutions ==&lt;br /&gt;
&lt;br /&gt;
=== My Solution ===&lt;br /&gt;
The current proposal most well supported from the email discussion thread, and the one which I feel makes most sense, is described here.&lt;br /&gt;
&lt;br /&gt;
The HTML spec already defines the &amp;quot;async&amp;quot; attribute for parser-inserted script tags, which when set to &amp;quot;true&amp;quot;, changes their execution order behavior to be like script-inserted script-elements (in IE/Webkit), which is that they load in parallel and execute &amp;quot;as fast as possible&amp;quot; (ostensibly because the author is expressing no dependencies between multiple such &amp;quot;async&amp;quot;-marked scripts). Parser-inserted script elements without &amp;quot;async&amp;quot; (or with it set to false) behave as before and expected, which is that they load in parallel but execute in order.&lt;br /&gt;
&lt;br /&gt;
However, the HTML spec does not define the &amp;quot;async&amp;quot; property (or any such behavior) for script-inserted script nodes (such as those created by a script loader). Instead, the spec implies that &amp;quot;async=true&amp;quot; like behavior is always true for such script-inserted script elements.&lt;br /&gt;
&lt;br /&gt;
What is proposed is:&lt;br /&gt;
&lt;br /&gt;
a) Script-inserted script elements should have (and respect the value of) an &amp;quot;async&amp;quot; property which is basically identical to the &amp;quot;async&amp;quot; attribute for parser-inserted script elements. That is, script elements with the &amp;quot;async&amp;quot; property set to &amp;quot;true&amp;quot; will behave accordingly, as will script elements with the &amp;quot;async&amp;quot; property set to false. &lt;br /&gt;
&lt;br /&gt;
Essentially, the proposal is to mirror the &amp;quot;async&amp;quot; attribute behavior of parser-inserted script elements as an &amp;quot;async&amp;quot; property on script-inserted script elements. This has the benefit of using an existing facility and extending it (from current spec) in a way that is sensisble and symmetric with its current definition.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EFEFEF&amp;quot;&amp;gt;&lt;br /&gt;
The scriptgroup or `readyState`  alternate proposals allow for dependency management to be done in high-level code.  The singular syncrhonized execution queue proposed here introduces artificial dependencies, undermining some of the benefits dynamic script loading provides.  &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
b) Furthermore, to aid in &amp;quot;feature-detection&amp;quot; of such new behavior, the proposal is to have the default value for the &amp;quot;async&amp;quot; property of script-inserted script elements be &amp;quot;true&amp;quot; (and of course the associated behavior thereof).&lt;br /&gt;
&lt;br /&gt;
There are two major benefits to (b). One is that it provides a way to feature test such new behavior by not just looking for the existence of the &amp;quot;async&amp;quot; property on script elements, but specifically that the default value is &amp;quot;true&amp;quot; (which is opposite of what it would currently/normally be). Secondly, defaulting to &amp;quot;async=true&amp;quot; behavior for script-inserted script elements would preserve the default behavior of IE and Webkit, meaning there&#039;d be less of a chance of breaking existing web content in either of those two browsers.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also important to note that there is no implied or requested effect or dependency between script-inserted script elements and parser-inserted script elements -- the two types of scripts would load and execute in entirely separate behavioral sandboxes.&lt;br /&gt;
&lt;br /&gt;
==== Proposal Amendment: Events ====&lt;br /&gt;
In addition to standardizing how scripts load and execute, it&#039;s also important to standardize the load and error events, and under what circumstances they fire, etc. Without reliable load/error events, the main proposal is not reliable and is thus unhelpful for the use-case.&lt;br /&gt;
&lt;br /&gt;
A script-inserted script element must fire the &amp;quot;load&amp;quot; event only once, when:&lt;br /&gt;
&lt;br /&gt;
a) immediately after the resource finishes loading, but before parsing/execution, AND&lt;br /&gt;
&lt;br /&gt;
b) the script element loads any non-empty content (that is, it was a successful HTTP request), AND&lt;br /&gt;
&lt;br /&gt;
c) the script element has either loaded from the remote location, or is loaded from the brower cache&lt;br /&gt;
&lt;br /&gt;
Specifically, the script &amp;quot;load&amp;quot; event must come immediately between the script element finishing loading and the script element being parsed/executed. If the script resource successfully loads, nothing should interrupt the sequence of fininshing loading, the &amp;quot;load&amp;quot; event firing, and the script being parsed/executed.&lt;br /&gt;
&lt;br /&gt;
A script-inserted script element must fire the &amp;quot;error&amp;quot; event only once, when:&lt;br /&gt;
&lt;br /&gt;
a) immediately after a loading failure for the resource is detected (that is, an HTTP error received, such as 404, 500, 503, etc).&lt;br /&gt;
&lt;br /&gt;
Either the &amp;quot;load&amp;quot; or &amp;quot;error&amp;quot; event, but not both, will fire, and only once, for every script-inserted script element.&lt;br /&gt;
&lt;br /&gt;
NOTE: &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events on script-inserted script elements must fire synchronously to ensure event reliability.&lt;br /&gt;
&lt;br /&gt;
A case may be made for adding the &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events as described here to parser-inserted script elements as well.&lt;br /&gt;
&lt;br /&gt;
==== Processing Model ====&lt;br /&gt;
Script inserted script elements will have an &amp;quot;async&amp;quot; property that defaults to &amp;quot;true&amp;quot;. If the author does not change the value, all such requested script loadings will be in their own &amp;quot;queue&amp;quot; and will default to &amp;quot;as fast as possible&amp;quot; execution behavior. For any script elements that the author sets &amp;quot;async=false&amp;quot;, those scripts will load in a separate &amp;quot;queue&amp;quot;, and will execute in insertion order only. Again, these two &amp;quot;queues&amp;quot; will operate strictly independent of each other.&lt;br /&gt;
&lt;br /&gt;
==== Processing Model Details (without the event amendment) ====&lt;br /&gt;
&lt;br /&gt;
When a script element node is created, if it is being flagged as parser-inserted, set its force-async flag to false. Otherwise, set its force-async flag to true. (Note that createContextualFragment, innerHTML and XSLTProcessor::transformToFragment-created scripts are not flagged as parser-inserted.) This flag setting happens before any attributes (even parser-set ones) are set on the node.&lt;br /&gt;
&lt;br /&gt;
When a previously-created script element node loses its parser-insertedness, if the element doesn&#039;t have the async content attribute, set the force-async flag to true and false otherwise.&lt;br /&gt;
&lt;br /&gt;
When a script element node obtains the async content attribute (via setAttribute, setAttributeNode, setAttributeNS, by the fragment parser or the XSLTProcessor adding the attribute, etc.), set the force-async flag to false. (Note that calling removeAttribute(&amp;quot;async&amp;quot;) doesn&#039;t modify the force-async flag.)&lt;br /&gt;
&lt;br /&gt;
The async IDL attribute must behave as follows:&lt;br /&gt;
* Upon setting, set the force-async flag to false and then reflect the async content attribute.&lt;br /&gt;
* Upon getting, if the force-async flag is true, return true. Otherwise, reflect the async content attribute.&lt;br /&gt;
&lt;br /&gt;
In step 13. of http://www.whatwg.org/specs/web-apps/current-work/#running-a-script before the case &amp;quot;If the element has a src attribute&amp;quot; add a case:&lt;br /&gt;
If the script has a src attribute and the async IDL property getter returns false,&lt;br /&gt;
The element must be added to the queue of ordered script-inserted external scripts of the Document of the script element at the time the running a script algorithm started.&lt;br /&gt;
&lt;br /&gt;
The task that the networking task source places on the task queue once the fetching algorithm has completed must run these steps:&lt;br /&gt;
# If the queue of ordered script-inserted external scripts is empty or the first script in the queue of ordered script-inserted external scripts has not been fetched yet, abort these steps.&lt;br /&gt;
# Execute the first script in the queue of ordered script-inserted external scripts.&lt;br /&gt;
# Remove the first script from queue of ordered script-inserted external scripts.&lt;br /&gt;
# Goto step #1.&lt;br /&gt;
&lt;br /&gt;
Modify step 5 of  http://www.whatwg.org/specs/web-apps/current-work/#the-end to say:&lt;br /&gt;
Spin the event loop until the set of scripts that will execute as soon as possible is empty and the queue of ordered script-inserted external scripts is empty.&lt;br /&gt;
&lt;br /&gt;
==== Limitations ==== &lt;br /&gt;
The two behaviors being identified solve either the case where no dependencies exist, or where a linear dependency chain exists (and which the script elements can be requested to execute in that order). It is possible that some authors have a more complex non-linear dependency chain that they would like to express. This would obviously require a much more complex API and spec change, and since that use-case has not (yet) surfaced as a particularly main-stream request, I believe it would be overengineering to try to address it with this proposed change set.&lt;br /&gt;
&lt;br /&gt;
In addition, it&#039;s been duly noted that it&#039;s undesirable (and potentially confusing/problematic) to intentionally build in the inconsistency of having the &amp;quot;async&amp;quot; attribute (for parser-inserted scripts) and the &amp;quot;async&amp;quot; property (for script-inserted scripts) have different default values (&amp;quot;false&amp;quot; for the attribute, &amp;quot;true&amp;quot; for the property).&lt;br /&gt;
&lt;br /&gt;
It&#039;s also been a point of discussion whether or not such a spec change has enough &amp;quot;carrot&amp;quot; to entice the browser vendors (namely IE and Webkit) to implement the behavior. Moreover, there&#039;s been some concern that if the default value for the &amp;quot;async&amp;quot; property were made to be &amp;quot;false&amp;quot; (like the attribute) to be more consistent and conservative, then it would possibly give the perception to IE and Webkit of &amp;quot;losing&amp;quot; some performance to cut out their default &amp;quot;as fast as possible&amp;quot; behavior.&lt;br /&gt;
&lt;br /&gt;
=== Alternate Proposals === &lt;br /&gt;
One early proposal on the email list was to introduce an entirely new property like &amp;quot;ordered&amp;quot; which an author could add to a script-inserted script element to instruct the browser to put it into the queue of execution-order-preserving script loadings. While such a property would address the use case, it introduces another property and thus more complicates the issue. It also fails to address the current spec inconsistency (which is confusing to new comers) that &amp;quot;async&amp;quot; is not a present/respected property in mirror of the attribute of the same name.&lt;br /&gt;
&lt;br /&gt;
Another suggestion was a &amp;quot;waitFor&amp;quot; property that would be added to script elements and would specify a list of one or more DOM id&#039;s of other script elements that the current script should &amp;quot;wait for&amp;quot; in terms of execution. Again, this would solve the use case, but in a more complicated way, and there are concerns that it would be too confusing for the normal use-case.&lt;br /&gt;
&lt;br /&gt;
Several suggestions have come in the form of creating explicit &amp;quot;preloading&amp;quot; (similar to &amp;amp;lt;link rel=prefetch&amp;gt;), but as described above, &amp;quot;preloading&amp;quot; to solve this use case is a non-ideal hack and highly susceptible to breakage if the script fails to be sent with proper caching headers.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also been suggested that since this type of behavior is somewhat complicated, it may be better to intentionally obfuscate or complicate any such facility in the HTML, so as to make the barrier-to-entry rather high and force users to know what they are doing before doing it.&lt;br /&gt;
&lt;br /&gt;
It&#039;s been suggested that &amp;quot;defer&amp;quot; already preserves execution order. However, &amp;quot;defer&amp;quot; is only defined for parser-inserted scripts, and thus is not applicable to the use-case in question from an on-demand point of view. Also, &amp;quot;defer&amp;quot; scripts explicitly way for DOMContentLoaded, even if they&#039;re ready to execute sooner. So this is less than desired.&lt;br /&gt;
&lt;br /&gt;
Yet another proposal is a &amp;quot;document.executeScripts()&amp;quot; API, where an author can specify multiple sets of scripts that can load in parallel and it will enforce their execution order. A variation on that same idea was to use the &amp;quot;importScripts&amp;quot; from the Web Workers spec, however &amp;quot;importScripts&amp;quot; is synchronous (undesirable performance wise, obviously). The main downside (besides extra API complication) to &amp;quot;document.executeScripts()&amp;quot; is that there seem to be quite a few script execution properties/behaviors (including &amp;quot;document.currentScript&amp;quot; and charset override) which would have to be duplicated into this API facility.&lt;br /&gt;
&lt;br /&gt;
==== &amp;quot;Script Group&amp;quot; element ====&lt;br /&gt;
One recent alternate proposal bears some special consideration, as it seems like it might be a decent option (although certainly more of a radical change for the spec and for browsers to implement). But it has the appearance of being pretty straightforward and semantic for authors to use, perhaps even more so than using &amp;quot;async&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The proposal is to create a new HTML element, called perhaps &amp;amp;lt;scriptGroup&amp;gt;, &amp;amp;lt;collection&amp;gt;, etc. Specifically, this element must be able to be inserted wherever a &amp;amp;lt;script&amp;gt; element can currently be inserted. The &amp;quot;script group&amp;quot; element is intended to signify that all script elements added to it must perserve insertion execution order. This element wouldn&#039;t have much (but still some, explained in a moment) meaning in a parser-inserted context, since parser-inserted scripts already preserve order among themselves.&lt;br /&gt;
&lt;br /&gt;
An advantage of the &amp;quot;script group&amp;quot; element would be to give a direct and easy way to attach event listeners (&amp;quot;load&amp;quot; and &amp;quot;error&amp;quot;) to the entire group, rather than having to internally track events for each element if all you care about is the final &amp;quot;load&amp;quot; event, for instance. In the case of event handling, the &amp;quot;script group&amp;quot; element would have perhaps some benefit even in parser-inserted (markup) context.&lt;br /&gt;
&lt;br /&gt;
The element would need to have an &amp;quot;id&amp;quot; property, and possibly attributes for &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events.&lt;br /&gt;
&lt;br /&gt;
A variation on how to look at this proposal is that a &amp;quot;script group&amp;quot; element could have an attribute/property on it (perhaps called &amp;quot;ordered&amp;quot;) which would allow the group to either be order preserved or not. This would make the &amp;quot;script group&amp;quot; element much more useful in the parser-inserted context, as it would sort of be a shortcut to setting &amp;quot;async=true&amp;quot; on all the child script elements.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;script group&amp;quot; element might look like this:&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group1&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;foo.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;bar.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      somethingInline();&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, with the &amp;quot;ordered&amp;quot; attribute to explicitly control ordering behavior for the group:&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group1&amp;quot; ordered=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;foo.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;bar.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      somethingInline();&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group2&amp;quot; ordered=&amp;quot;false&amp;quot; onload=&amp;quot;alldone();&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;baz.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;far.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;zab.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the &amp;quot;script group&amp;quot; element is definitely more complicated to define and implement, it does have some semantic advantages for authors, and it also would significantly reduce the internal complexity of script loaders like LABjs. It would give authors (either directly or through script loaders) the flexibility to group scripts together into one of the two aforementioned behaviors (execution &amp;quot;as fast as possible&amp;quot; or &amp;quot;in insertion order&amp;quot;), and to easily access both behaviors in the same page.&lt;br /&gt;
&lt;br /&gt;
==== Explicit support for &amp;quot;text/cache&amp;quot; MIME type behavior ====&lt;br /&gt;
Yet another alternate proposal has been suggested in the [[Talk:Dynamic_Script_Execution_Order]] thread. &lt;br /&gt;
&lt;br /&gt;
Essentially, the proposal is that &amp;amp;lt;script&amp;gt; tags directly support being declared with a `type` value of &amp;quot;text/cache&amp;quot;. The behavior would be that the script resource is fetched, as the load events fired, as normal, but that the script itself would not be executed. Then later, at the desired time, the script in that element could be executed by changing the `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The browser would probably need to keep track (via some internal flag) that the script node is only ever executed once. Also, it&#039;s an open question if such a &amp;quot;cached&amp;quot; script node should be able to have its script content modified before execution via the `text` property.&lt;br /&gt;
&lt;br /&gt;
==== readyState &amp;quot;preloading&amp;quot; ====&lt;br /&gt;
Per the suggestion/comment added to the above [[Dynamic_Script_Execution_Order#Current_Limitations|Current Limitations]] section, it&#039;s been suggested that IE&#039;s current behavior with respect to the `readyState` property can adequately serve the use-case in question.&lt;br /&gt;
&lt;br /&gt;
The idea is that IE will begin fetching into the cache a script resource as soon as the `src` attribute of the dynamic script element is set. But IE will not execute the script (even if it finishes loading) until the script element is added to the DOM. However, the `readyState` property of the element, combined with the `onreadystatechange` handler listening for changes, can detect when the script has finished loading, by receiving the &amp;quot;loaded&amp;quot; value.&lt;br /&gt;
&lt;br /&gt;
In this way, a script loader could &amp;quot;preload&amp;quot; a set of scripts all in parallel, but control their execution order by delaying the appending of the element to the DOM until execution is desired.&lt;br /&gt;
&lt;br /&gt;
[[Category:Feature Request|Dynamic Script Execution Order]]&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Dynamic_Script_Execution_Order&amp;diff=5612</id>
		<title>Dynamic Script Execution Order</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Dynamic_Script_Execution_Order&amp;diff=5612"/>
		<updated>2010-12-14T21:53:30Z</updated>

		<summary type="html">&lt;p&gt;Serverherder: /* Current Limitations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is intended to formalize the discussion around an important but currently underserved use-case (in both spec and various browser implementations): the need for a dynamic script loading facility that can download resources in parallel but ensure that they execute serially in insertion order, for dependency reasons.&lt;br /&gt;
&lt;br /&gt;
A long email thread on the W3C public-html list, which began [http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html here] and for which a recent message is [http://lists.w3.org/Archives/Public/public-html/2010Oct/0415.html here], has been discussing this problem, but the email thread is becoming unruly and hard to track, so this wiki page will now be the official location to discuss the topic.&lt;br /&gt;
&lt;br /&gt;
Briefly, this issue has arisen because recent &amp;quot;nightlies&amp;quot; changes in both Mozilla Gecko and Webkit have broken the ability for script-loaders like [http://labjs.com LABjs] to be able to download scripts in parallel but ensure their execution order. As a result of the discussion, it&#039;s become apparent that both the spec for, and various current browser implementations around, dynamic script loading is incomplete in addressing this use case, and that some change needs to occur.&lt;br /&gt;
&lt;br /&gt;
There is one main proposal that has surfaced from the discussions, with several other alternatives having been discussed. This page will try to distill the long email thread down and clearly present the main proposal, objections, and alternative suggestions.&lt;br /&gt;
&lt;br /&gt;
Please feel free to join the discussion of this topic in the [[Talk:Dynamic_Script_Execution_Order]] area.&lt;br /&gt;
&lt;br /&gt;
== Use Case Description ==&lt;br /&gt;
Script tags/elements can either: &lt;br /&gt;
&lt;br /&gt;
a) appear in the HTML markup (&amp;quot;parser-inserted&amp;quot;), OR&lt;br /&gt;
&lt;br /&gt;
b) be dynamically appended to the DOM using document.createElement() (&amp;quot;script-inserted&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Parser-inserted script tags, up until recent browser versions, had the undesirable performance behavior of loading and executing serially, blocking everything else while doing so. Recently, many browsers have improved the situation by loading the scripts in parallel, but still executing them in order.&lt;br /&gt;
&lt;br /&gt;
On-demand (or dynamic) script loading has emerged in recent years for a variety of different reasons, most notably the performance improvements to address such concerns. It is desired by many different scenarios to be able to download scripts to a page completely independently of the loading of the rest of a page&#039;s resources, or even well after a page has finished loading (&amp;quot;on-demand&amp;quot;).  &lt;br /&gt;
&lt;br /&gt;
Recent additions to HTML spec such as &amp;quot;defer&amp;quot; and &amp;quot;async&amp;quot; were intended to address the use-case for parser-inserted script elements, but their behaviors have been unhelpful for the on-demand loading use-case (script-inserted script elements).&lt;br /&gt;
&lt;br /&gt;
Thus, script loaders (like [http://labjs.com LABjs]) were developed to give page authors an easy way to specify one or more scripts to load (regardless of when in the life-time of the page that loading is requested), and for as many of them as possible to load in parallel, and for those scripts to be loadable from any local or remote domain location, and for the script loader to be able to control the execution order (if the usage of the script loader&#039;s API expresses the need to) to preserve dependencies between the scripts.&lt;br /&gt;
&lt;br /&gt;
Sometimes, dynamic script loading is used to load totally independent scripts, and thus &amp;quot;as fast as possible&amp;quot; execution is desired. Other times (and possibly more frequently), multiple scripts are loaded with some  dependencies among them, requiring them to execute in a certain order. &lt;br /&gt;
&lt;br /&gt;
What is needed is some facility by which a script loader can express that dynamic script loading either does or does not need execution order preserved among the queue of requested script loadings.&lt;br /&gt;
&lt;br /&gt;
=== Current Limitations ===&lt;br /&gt;
Unfortunately, browser behavior around script-inserted script elements and their loading and execution behavior is splintered. There are, at present, two main camps of behavior:&lt;br /&gt;
&lt;br /&gt;
a) in IE and Webkit (including Chrome), the default behavior for script-inserted script elements is for them all to execute in &amp;quot;as fast as possible&amp;quot; mode, meaning there&#039;s no guarantee about ordering. This effectively makes on-demand (dynamic) script loading impossible to work in parallel-mode if the resources in question have dependencies -- the only straight-forward way to handle things is to load each file and execute, serially, losing the parallel loading performance benefits.&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
I&#039;m not sure if this is the case.  &lt;br /&gt;
&lt;br /&gt;
IE will start fetching resources without execution simply by setting the src attribute.  Scripts will not execute, however, until they are added to the document.  Since IE supports the readyState attribute and readystatechange event, it&#039;s possible to load scripts in parallel and execute them in order without resorting to invalid type attribute hack-ery.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color:white&amp;quot; lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
script= document.createElement(&amp;quot;SCRIPT&amp;quot;); &lt;br /&gt;
script.onreadystatechange= function(){ &lt;br /&gt;
    if(this.readyState == &#039;loaded&#039;)&lt;br /&gt;
          /* &lt;br /&gt;
             Network fetch is now complete, following&lt;br /&gt;
             triggers synchronous execution.  &lt;br /&gt;
          */&lt;br /&gt;
          document.body.appendChild(this); &lt;br /&gt;
    else if(this.readyState == &amp;quot;complete&amp;quot;)&lt;br /&gt;
          this.onreadystatechange= null; &lt;br /&gt;
}&lt;br /&gt;
script.src= &amp;quot;foo.js&amp;quot;; &lt;br /&gt;
/* Network fetching begins now */&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
b) in Gecko and Opera, the default behavior for script-inserted script elements is for them all to load in parallel, but execute serially in insertion order. Technically, this makes it impossible to dynamically load independent script elements and have them execute in &amp;quot;as fast as possible&amp;quot; mode.&lt;br /&gt;
&lt;br /&gt;
As described above, both behaviors are desirable under different circumstances, but each of the two camps provides only one behavior, and no way to straightforwardly achieve the other. This obviously creates a big nightmare interoperability-wise when trying to provide a general script loader cross-browser.&lt;br /&gt;
&lt;br /&gt;
Since it is observed that the behavior in (a) is more detrimental (race-condition wise) for the case where dependencies exist, script loaders like LABjs had to find some way around this problem while still attempting the best possible parallel loading performance. However, the trick used is hacky and not completely reliable -- yet it is the best way to solve the use-case in &amp;lt;s&amp;gt;IE and &amp;lt;/s&amp;gt;Webkit. &lt;br /&gt;
&lt;br /&gt;
For Gecko/Opera, the concession was just (silently) made that the lesser-common use case of &amp;quot;as fast as possible&amp;quot; wasn&#039;t possible, but degraded fine to &amp;quot;insertion order execution&amp;quot;, while keeping the parallel loading benefits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
Gecko&#039;s strict execution order creates dependencies between scripts which are unrelated and prevents the ability mitigate the impact of server outages / network latency.  This is exacerbated by the fact that Gecko, unlike IE and WebKit, provides no mechanism to &amp;lt;b&amp;gt;remove&amp;lt;/b&amp;gt; scripts from the execution queue. &lt;br /&gt;
&lt;br /&gt;
Consider the case where JSONP is used to provide auto-completion.  The user types &amp;quot;hello&amp;quot; and the JSONP request is made; however, the &amp;quot;currently&amp;quot; loading script is out-of-date as soon as the user modifies his search to &amp;quot;hello world&amp;quot;.  Gecko&#039;s algorithm requires the out-of-date request load and execute before the second request.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Recently, Gecko landed a [http://hg.mozilla.org/mozilla-central/rev/a60414d076b5 patch] to the trunk that stopped Gecko&#039;s existing behavior of preserving execution order, making script-inserted script elements now execute in &amp;quot;as fast as possible&amp;quot; mode similiar to IE/Webkit. Unfortunately, the &amp;quot;workaround&amp;quot; used in IE/Webkit (described in the next section) for dealing with parallel loading and execution-order dependencies does not work in Gecko, which means presently the use-case in question is now broken in Gecko trunk/FF4 nightlies.&lt;br /&gt;
&lt;br /&gt;
Moreover, Webkit recently landed a [http://trac.webkit.org/changeset/67245 patch] to the trunk that stopped Webkit&#039;s non-standard but long-held behavior (also used in the &amp;quot;workaround&amp;quot; described in the next section) of loading into cache script resources with an unrecognized &amp;quot;type&amp;quot; value, but silently not executing them. This behvaior (while hacky) is central to being able to address the use-case in question in Webkit, so at present, Webkit nightlies are now also entirely broken on the use-case (though in a different way than Gecko).&lt;br /&gt;
&lt;br /&gt;
Both the Gecko change and the Webkit change are well-intentioned, as they are bringing the respective browser more in line with the HTML spec. However, what&#039;s really been demonstrated is that the HTML spec is not properly handling this use-case, and so the goal is not to address the browser issues raised with more awkward hacks, but to address the shortcomings of the spec first, and then encourage all browsers to adhere to such.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background-color: #EEEEEE&amp;quot;&amp;gt; &lt;br /&gt;
Considering Internet Explorer&#039;s readyState implementation provides a means of both parallel loading and preserving execution order can be achieved, perhaps its &amp;quot;readyState&amp;quot; property and onreadystatechange event should be included. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Current Usage and Workarounds ===&lt;br /&gt;
To work around the limitation in IE/Webkit(prior to the above noted patch) of not being able to rely on script order execution for parallel loaded scripts, a &amp;quot;preloading&amp;quot; trick was developed. This trick relied on non-standard (but long-held) behavior in these browsers that a script-inserted script element with an unrecognized &amp;quot;type&amp;quot; value (such as &amp;quot;script/cache&amp;quot;) would be fetched/loaded, but would not execute. This had the effect of loading the resource into cache, and then firing the &amp;quot;load&amp;quot; handlers to let the page know when the resource was completely in cache. &lt;br /&gt;
&lt;br /&gt;
Assuming that the resource was served with proper caching headers, and was in fact in the cache, it could then be executed (nearly) immediately when it was the proper execution order time by re-requesting the same resource via another script-inserted script element with the proper &amp;quot;text/javascript&amp;quot; type value, pulling the resource from the cache and executing it, without another server round-trip.&lt;br /&gt;
&lt;br /&gt;
Of course, the assumption of proper cache headers is a huge one, and not at all reliable. Some recent estimates by performance optimization specialists have suggested as much as 70% of scripts across the internet are not served with proper caching headers, which means that such scripts would be completely ineffective if loaded using this (or a similar) technique. The script resource would end up being loaded completely a second-time, and the &amp;quot;near immediate&amp;quot; execution would obviously be false, and thus race conditions would ensue.&lt;br /&gt;
&lt;br /&gt;
It&#039;s important to note at this point that the new &amp;amp;lt;link rel=prefetch&amp;gt; facility has been suggested as a better workaround, but it suffers the same ill-fated assumption of script cacheability. Still others have suggested &amp;quot;new Image().src=...&amp;quot; or the [http://www.phpied.com/preload-then-execute/ &amp;amp;lt;object&amp;amp;gt; preloading trick] suggested by Stoyan Stefanov. Again, these tricks unwisely assume cacheability, for the &amp;quot;preloading&amp;quot; trick to solve the use-case in question.&lt;br /&gt;
&lt;br /&gt;
=== At Risk ===&lt;br /&gt;
Currently, there are several large/popular web sites which are either currently (or who intend to soon) use LABjs in such a way as to run afoul of the new Gecko and Webkit behavioral changes with LABjs failing to operate properly. It&#039;s important to note that the problems of race conditions can be subtle and hard to detect, and so merely loading up such sites and failing to observe overt failure is not sufficient.&lt;br /&gt;
&lt;br /&gt;
Sites which are known to have LABjs loading techniques in place with currently broken (or susceptible to such breakage in the near future) behavior are:&lt;br /&gt;
&lt;br /&gt;
* [http://twitter.com Twitter]&lt;br /&gt;
* [http://zappos.com Zappos]&lt;br /&gt;
* [http://vimeo.com Vimeo]&lt;br /&gt;
* [http://mefeedia.com MeFeedia]&lt;br /&gt;
* [http://blog.getify.com Getify Solutions blog (my blog)]&lt;br /&gt;
* [http://flensed.com flensed Flash+JavaScript browser shims (cross-domain Ajax, cross-browser cookies, etc)]&lt;br /&gt;
&lt;br /&gt;
Rather than getting hung up in the syntax of usage in LABjs that is or is not going to break, it&#039;s best to just think of the problem this way:&lt;br /&gt;
&lt;br /&gt;
Does a site need to load more than one script, at least one of which comes from a remote domain location (like a CDN), and for which among the scripts there&#039;s at least one execution-order dependency among them? If so, then that site is susceptible to the current/future breakage if the HTML spec (and browsers) do not address this use case.&lt;br /&gt;
&lt;br /&gt;
A common example (in use on many sites) of such might be loading:&lt;br /&gt;
&lt;br /&gt;
* jQuery from the CDN&lt;br /&gt;
* jQuery-UI from the CDN&lt;br /&gt;
* plugins and usage code in one or more local files&lt;br /&gt;
* Google Analytics from the Google domain&lt;br /&gt;
&lt;br /&gt;
Note that the emergence of popular script frameworks and their hosting on public CDN&#039;s is leading to more and more sites loading scripts from both local and remote locations, and also to loading more files that have dependencies (rather than the practice of concat&#039;ing all files into one file to avoid dependency issues).&lt;br /&gt;
&lt;br /&gt;
Any site which fits a profile like the above, and which might currently (many do), or in the future want to, use a script loader to improve their loading performance, will fail to achieve what they want cross-browser and in a performant way, if the HTML spec (and browsers) do not address the use case.&lt;br /&gt;
&lt;br /&gt;
=== Benefits ===&lt;br /&gt;
The benefits of addressing both behaviors directly (without &amp;quot;preloading&amp;quot; tricks and bad assumption reliance) have been implied in the above discussion, but in short are:&lt;br /&gt;
&lt;br /&gt;
a) clear and simplified code for script loaders, which leads to easier use by authors of more pages, which in turn leads to better web performance (as demonstrated clearly by intelligent script loading techniques as compared to just simple &amp;amp;lt;script&amp;gt; tags in HTML markup)&lt;br /&gt;
&lt;br /&gt;
b) full access to either/both of the execution-order behaviors (as the author sees fit), regardless of browser&lt;br /&gt;
&lt;br /&gt;
c) avoiding reliance on bad assumptions (like cacheability) as a sufficient way to address the use-case&lt;br /&gt;
&lt;br /&gt;
=== External Discussions of this Feature ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://lists.w3.org/Archives/Public/public-html/2010Oct/0088.html W3C public-html email thread]&amp;lt;/cite&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://www.w3.org/Bugs/Public/show_bug.cgi?id=11295 W3C Bug #11295]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[https://bugzilla.mozilla.org/show_bug.cgi?id=602838 Mozilla Bug #602838]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[https://bugs.webkit.org/show_bug.cgi?id=50115 Webkit Bug #50115]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://hsivonen.iki.fi/script-execution/ HTML5 Script Execution Changes in Firefox 4 Beta 7]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://blog.getify.com/2010/10/labjs-w3c-brief-update/ LABjs and W3C... brief update]&amp;lt;/cite&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* &amp;lt;cite&amp;gt;[http://blog.getify.com/2010/10/ff4-script-loaders-and-order-preservation/ FF4, script loaders, and order preservation]&amp;lt;/cite&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Proposed Solutions ==&lt;br /&gt;
&lt;br /&gt;
=== My Solution ===&lt;br /&gt;
The current proposal most well supported from the email discussion thread, and the one which I feel makes most sense, is described here.&lt;br /&gt;
&lt;br /&gt;
The HTML spec already defines the &amp;quot;async&amp;quot; attribute for parser-inserted script tags, which when set to &amp;quot;true&amp;quot;, changes their execution order behavior to be like script-inserted script-elements (in IE/Webkit), which is that they load in parallel and execute &amp;quot;as fast as possible&amp;quot; (ostensibly because the author is expressing no dependencies between multiple such &amp;quot;async&amp;quot;-marked scripts). Parser-inserted script elements without &amp;quot;async&amp;quot; (or with it set to false) behave as before and expected, which is that they load in parallel but execute in order.&lt;br /&gt;
&lt;br /&gt;
However, the HTML spec does not define the &amp;quot;async&amp;quot; property (or any such behavior) for script-inserted script nodes (such as those created by a script loader). Instead, the spec implies that &amp;quot;async=true&amp;quot; like behavior is always true for such script-inserted script elements.&lt;br /&gt;
&lt;br /&gt;
What is proposed is:&lt;br /&gt;
&lt;br /&gt;
a) Script-inserted script elements should have (and respect the value of) an &amp;quot;async&amp;quot; property which is basically identical to the &amp;quot;async&amp;quot; attribute for parser-inserted script elements. That is, script elements with the &amp;quot;async&amp;quot; property set to &amp;quot;true&amp;quot; will behave accordingly, as will script elements with the &amp;quot;async&amp;quot; property set to false. &lt;br /&gt;
&lt;br /&gt;
Essentially, the proposal is to mirror the &amp;quot;async&amp;quot; attribute behavior of parser-inserted script elements as an &amp;quot;async&amp;quot; property on script-inserted script elements. This has the benefit of using an existing facility and extending it (from current spec) in a way that is sensisble and symmetric with its current definition.&lt;br /&gt;
&lt;br /&gt;
b) Furthermore, to aid in &amp;quot;feature-detection&amp;quot; of such new behavior, the proposal is to have the default value for the &amp;quot;async&amp;quot; property of script-inserted script elements be &amp;quot;true&amp;quot; (and of course the associated behavior thereof).&lt;br /&gt;
&lt;br /&gt;
There are two major benefits to (b). One is that it provides a way to feature test such new behavior by not just looking for the existence of the &amp;quot;async&amp;quot; property on script elements, but specifically that the default value is &amp;quot;true&amp;quot; (which is opposite of what it would currently/normally be). Secondly, defaulting to &amp;quot;async=true&amp;quot; behavior for script-inserted script elements would preserve the default behavior of IE and Webkit, meaning there&#039;d be less of a chance of breaking existing web content in either of those two browsers.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also important to note that there is no implied or requested effect or dependency between script-inserted script elements and parser-inserted script elements -- the two types of scripts would load and execute in entirely separate behavioral sandboxes.&lt;br /&gt;
&lt;br /&gt;
==== Proposal Amendment: Events ====&lt;br /&gt;
In addition to standardizing how scripts load and execute, it&#039;s also important to standardize the load and error events, and under what circumstances they fire, etc. Without reliable load/error events, the main proposal is not reliable and is thus unhelpful for the use-case.&lt;br /&gt;
&lt;br /&gt;
A script-inserted script element must fire the &amp;quot;load&amp;quot; event only once, when:&lt;br /&gt;
&lt;br /&gt;
a) immediately after the resource finishes loading, but before parsing/execution, AND&lt;br /&gt;
&lt;br /&gt;
b) the script element loads any non-empty content (that is, it was a successful HTTP request), AND&lt;br /&gt;
&lt;br /&gt;
c) the script element has either loaded from the remote location, or is loaded from the brower cache&lt;br /&gt;
&lt;br /&gt;
Specifically, the script &amp;quot;load&amp;quot; event must come immediately between the script element finishing loading and the script element being parsed/executed. If the script resource successfully loads, nothing should interrupt the sequence of fininshing loading, the &amp;quot;load&amp;quot; event firing, and the script being parsed/executed.&lt;br /&gt;
&lt;br /&gt;
A script-inserted script element must fire the &amp;quot;error&amp;quot; event only once, when:&lt;br /&gt;
&lt;br /&gt;
a) immediately after a loading failure for the resource is detected (that is, an HTTP error received, such as 404, 500, 503, etc).&lt;br /&gt;
&lt;br /&gt;
Either the &amp;quot;load&amp;quot; or &amp;quot;error&amp;quot; event, but not both, will fire, and only once, for every script-inserted script element.&lt;br /&gt;
&lt;br /&gt;
NOTE: &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events on script-inserted script elements must fire synchronously to ensure event reliability.&lt;br /&gt;
&lt;br /&gt;
A case may be made for adding the &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events as described here to parser-inserted script elements as well.&lt;br /&gt;
&lt;br /&gt;
==== Processing Model ====&lt;br /&gt;
Script inserted script elements will have an &amp;quot;async&amp;quot; property that defaults to &amp;quot;true&amp;quot;. If the author does not change the value, all such requested script loadings will be in their own &amp;quot;queue&amp;quot; and will default to &amp;quot;as fast as possible&amp;quot; execution behavior. For any script elements that the author sets &amp;quot;async=false&amp;quot;, those scripts will load in a separate &amp;quot;queue&amp;quot;, and will execute in insertion order only. Again, these two &amp;quot;queues&amp;quot; will operate strictly independent of each other.&lt;br /&gt;
&lt;br /&gt;
==== Processing Model Details (without the event amendment) ====&lt;br /&gt;
&lt;br /&gt;
When a script element node is created, if it is being flagged as parser-inserted, set its force-async flag to false. Otherwise, set its force-async flag to true. (Note that createContextualFragment, innerHTML and XSLTProcessor::transformToFragment-created scripts are not flagged as parser-inserted.) This flag setting happens before any attributes (even parser-set ones) are set on the node.&lt;br /&gt;
&lt;br /&gt;
When a previously-created script element node loses its parser-insertedness, if the element doesn&#039;t have the async content attribute, set the force-async flag to true and false otherwise.&lt;br /&gt;
&lt;br /&gt;
When a script element node obtains the async content attribute (via setAttribute, setAttributeNode, setAttributeNS, by the fragment parser or the XSLTProcessor adding the attribute, etc.), set the force-async flag to false. (Note that calling removeAttribute(&amp;quot;async&amp;quot;) doesn&#039;t modify the force-async flag.)&lt;br /&gt;
&lt;br /&gt;
The async IDL attribute must behave as follows:&lt;br /&gt;
* Upon setting, set the force-async flag to false and then reflect the async content attribute.&lt;br /&gt;
* Upon getting, if the force-async flag is true, return true. Otherwise, reflect the async content attribute.&lt;br /&gt;
&lt;br /&gt;
In step 13. of http://www.whatwg.org/specs/web-apps/current-work/#running-a-script before the case &amp;quot;If the element has a src attribute&amp;quot; add a case:&lt;br /&gt;
If the script has a src attribute and the async IDL property getter returns false,&lt;br /&gt;
The element must be added to the queue of ordered script-inserted external scripts of the Document of the script element at the time the running a script algorithm started.&lt;br /&gt;
&lt;br /&gt;
The task that the networking task source places on the task queue once the fetching algorithm has completed must run these steps:&lt;br /&gt;
# If the queue of ordered script-inserted external scripts is empty or the first script in the queue of ordered script-inserted external scripts has not been fetched yet, abort these steps.&lt;br /&gt;
# Execute the first script in the queue of ordered script-inserted external scripts.&lt;br /&gt;
# Remove the first script from queue of ordered script-inserted external scripts.&lt;br /&gt;
# Goto step #1.&lt;br /&gt;
&lt;br /&gt;
Modify step 5 of  http://www.whatwg.org/specs/web-apps/current-work/#the-end to say:&lt;br /&gt;
Spin the event loop until the set of scripts that will execute as soon as possible is empty and the queue of ordered script-inserted external scripts is empty.&lt;br /&gt;
&lt;br /&gt;
==== Limitations ==== &lt;br /&gt;
The two behaviors being identified solve either the case where no dependencies exist, or where a linear dependency chain exists (and which the script elements can be requested to execute in that order). It is possible that some authors have a more complex non-linear dependency chain that they would like to express. This would obviously require a much more complex API and spec change, and since that use-case has not (yet) surfaced as a particularly main-stream request, I believe it would be overengineering to try to address it with this proposed change set.&lt;br /&gt;
&lt;br /&gt;
In addition, it&#039;s been duly noted that it&#039;s undesirable (and potentially confusing/problematic) to intentionally build in the inconsistency of having the &amp;quot;async&amp;quot; attribute (for parser-inserted scripts) and the &amp;quot;async&amp;quot; property (for script-inserted scripts) have different default values (&amp;quot;false&amp;quot; for the attribute, &amp;quot;true&amp;quot; for the property).&lt;br /&gt;
&lt;br /&gt;
It&#039;s also been a point of discussion whether or not such a spec change has enough &amp;quot;carrot&amp;quot; to entice the browser vendors (namely IE and Webkit) to implement the behavior. Moreover, there&#039;s been some concern that if the default value for the &amp;quot;async&amp;quot; property were made to be &amp;quot;false&amp;quot; (like the attribute) to be more consistent and conservative, then it would possibly give the perception to IE and Webkit of &amp;quot;losing&amp;quot; some performance to cut out their default &amp;quot;as fast as possible&amp;quot; behavior.&lt;br /&gt;
&lt;br /&gt;
=== Alternate Proposals === &lt;br /&gt;
One early proposal on the email list was to introduce an entirely new property like &amp;quot;ordered&amp;quot; which an author could add to a script-inserted script element to instruct the browser to put it into the queue of execution-order-preserving script loadings. While such a property would address the use case, it introduces another property and thus more complicates the issue. It also fails to address the current spec inconsistency (which is confusing to new comers) that &amp;quot;async&amp;quot; is not a present/respected property in mirror of the attribute of the same name.&lt;br /&gt;
&lt;br /&gt;
Another suggestion was a &amp;quot;waitFor&amp;quot; property that would be added to script elements and would specify a list of one or more DOM id&#039;s of other script elements that the current script should &amp;quot;wait for&amp;quot; in terms of execution. Again, this would solve the use case, but in a more complicated way, and there are concerns that it would be too confusing for the normal use-case.&lt;br /&gt;
&lt;br /&gt;
Several suggestions have come in the form of creating explicit &amp;quot;preloading&amp;quot; (similar to &amp;amp;lt;link rel=prefetch&amp;gt;), but as described above, &amp;quot;preloading&amp;quot; to solve this use case is a non-ideal hack and highly susceptible to breakage if the script fails to be sent with proper caching headers.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also been suggested that since this type of behavior is somewhat complicated, it may be better to intentionally obfuscate or complicate any such facility in the HTML, so as to make the barrier-to-entry rather high and force users to know what they are doing before doing it.&lt;br /&gt;
&lt;br /&gt;
It&#039;s been suggested that &amp;quot;defer&amp;quot; already preserves execution order. However, &amp;quot;defer&amp;quot; is only defined for parser-inserted scripts, and thus is not applicable to the use-case in question from an on-demand point of view. Also, &amp;quot;defer&amp;quot; scripts explicitly way for DOMContentLoaded, even if they&#039;re ready to execute sooner. So this is less than desired.&lt;br /&gt;
&lt;br /&gt;
Yet another proposal is a &amp;quot;document.executeScripts()&amp;quot; API, where an author can specify multiple sets of scripts that can load in parallel and it will enforce their execution order. A variation on that same idea was to use the &amp;quot;importScripts&amp;quot; from the Web Workers spec, however &amp;quot;importScripts&amp;quot; is synchronous (undesirable performance wise, obviously). The main downside (besides extra API complication) to &amp;quot;document.executeScripts()&amp;quot; is that there seem to be quite a few script execution properties/behaviors (including &amp;quot;document.currentScript&amp;quot; and charset override) which would have to be duplicated into this API facility.&lt;br /&gt;
&lt;br /&gt;
==== &amp;quot;Script Group&amp;quot; element ====&lt;br /&gt;
One recent alternate proposal bears some special consideration, as it seems like it might be a decent option (although certainly more of a radical change for the spec and for browsers to implement). But it has the appearance of being pretty straightforward and semantic for authors to use, perhaps even more so than using &amp;quot;async&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The proposal is to create a new HTML element, called perhaps &amp;amp;lt;scriptGroup&amp;gt;, &amp;amp;lt;collection&amp;gt;, etc. Specifically, this element must be able to be inserted wherever a &amp;amp;lt;script&amp;gt; element can currently be inserted. The &amp;quot;script group&amp;quot; element is intended to signify that all script elements added to it must perserve insertion execution order. This element wouldn&#039;t have much (but still some, explained in a moment) meaning in a parser-inserted context, since parser-inserted scripts already preserve order among themselves.&lt;br /&gt;
&lt;br /&gt;
An advantage of the &amp;quot;script group&amp;quot; element would be to give a direct and easy way to attach event listeners (&amp;quot;load&amp;quot; and &amp;quot;error&amp;quot;) to the entire group, rather than having to internally track events for each element if all you care about is the final &amp;quot;load&amp;quot; event, for instance. In the case of event handling, the &amp;quot;script group&amp;quot; element would have perhaps some benefit even in parser-inserted (markup) context.&lt;br /&gt;
&lt;br /&gt;
The element would need to have an &amp;quot;id&amp;quot; property, and possibly attributes for &amp;quot;load&amp;quot; and &amp;quot;error&amp;quot; events.&lt;br /&gt;
&lt;br /&gt;
A variation on how to look at this proposal is that a &amp;quot;script group&amp;quot; element could have an attribute/property on it (perhaps called &amp;quot;ordered&amp;quot;) which would allow the group to either be order preserved or not. This would make the &amp;quot;script group&amp;quot; element much more useful in the parser-inserted context, as it would sort of be a shortcut to setting &amp;quot;async=true&amp;quot; on all the child script elements.&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;script group&amp;quot; element might look like this:&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group1&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;foo.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;bar.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      somethingInline();&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or, with the &amp;quot;ordered&amp;quot; attribute to explicitly control ordering behavior for the group:&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group1&amp;quot; ordered=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;foo.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;bar.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      somethingInline();&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;scriptGroup id=&amp;quot;group2&amp;quot; ordered=&amp;quot;false&amp;quot; onload=&amp;quot;alldone();&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;baz.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;far.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;amp;lt;script src=&amp;quot;zab.js&amp;quot;&amp;gt;&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/scriptGroup&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the &amp;quot;script group&amp;quot; element is definitely more complicated to define and implement, it does have some semantic advantages for authors, and it also would significantly reduce the internal complexity of script loaders like LABjs. It would give authors (either directly or through script loaders) the flexibility to group scripts together into one of the two aforementioned behaviors (execution &amp;quot;as fast as possible&amp;quot; or &amp;quot;in insertion order&amp;quot;), and to easily access both behaviors in the same page.&lt;br /&gt;
&lt;br /&gt;
==== Explicit support for &amp;quot;text/cache&amp;quot; MIME type behavior ====&lt;br /&gt;
Yet another alternate proposal has been suggested in the [[Talk:Dynamic_Script_Execution_Order]] thread. &lt;br /&gt;
&lt;br /&gt;
Essentially, the proposal is that &amp;amp;lt;script&amp;gt; tags directly support being declared with a `type` value of &amp;quot;text/cache&amp;quot;. The behavior would be that the script resource is fetched, as the load events fired, as normal, but that the script itself would not be executed. Then later, at the desired time, the script in that element could be executed by changing the `type` value from &amp;quot;text/cache&amp;quot; to &amp;quot;text/javascript&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The browser would probably need to keep track (via some internal flag) that the script node is only ever executed once. Also, it&#039;s an open question if such a &amp;quot;cached&amp;quot; script node should be able to have its script content modified before execution via the `text` property.&lt;br /&gt;
&lt;br /&gt;
[[Category:Feature Request|Dynamic Script Execution Order]]&lt;/div&gt;</summary>
		<author><name>Serverherder</name></author>
	</entry>
</feed>