Skip to content
Permalink
Browse files
[] (0) Dramatically simplify <script defer> and <script async> handling.
Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id=7792

git-svn-id: http://svn.whatwg.org/webapps@4098 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information
Hixie committed Oct 9, 2009
1 parent 8e7add9 commit b7a9d94
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 202 deletions.
129 index
@@ -12081,9 +12081,9 @@ people expect to have work and what is necessary.
support <code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> (and not <code title=attr-script-async><a href=#attr-script-async>async</a></code>) to fall back to the <code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> behavior instead of the
synchronous blocking behavior that is the default.</p>

<p>If the <code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> attribute is
specified, the <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute
must also be specified.</p>
<p>If one or both of the <code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> and <code title=attr-script-async><a href=#attr-script-async>async</a></code> attributes are specified, the
<code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute must also be
specified.</p>

<p>Changing the <code title=attr-script-src><a href=#attr-script-src>src</a></code>, <code title=attr-script-type><a href=#attr-script-type>type</a></code>, <code title=attr-script-charset><a href=#attr-script-charset>charset</a></code>, <code title=attr-script-async><a href=#attr-script-async>async</a></code>, and <code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> attributes dynamically has no
direct effect; these attribute are only used <span class=impl>at
@@ -12246,35 +12246,20 @@ people expect to have work and what is necessary.
<p>Then, the first of the following options that describes the
situation must be followed:</p>

<dl class=switch><dt>If the document is still being parsed, and the element has a
<code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> attribute, and the
element has a <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute,
and the element does not have an <code title=attr-script-async><a href=#attr-script-async>async</a></code> attribute</dt>
<dl class=switch><dt>If the element has a <code title=attr-script-src><a href=#attr-script-src>src</a></code>
attribute, and the element has a <code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> attribute, and the element
has been flagged as <a href=#parser-inserted>"parser-inserted"</a>, and the
element does not have an <code title=attr-script-async><a href=#attr-script-async>async</a></code> attribute</dt>

<dd>The element must be added to the end of the <a href=#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list of
scripts that will execute when the document has finished
parsing</a>.

</dd>


<dt>If the element has an <code title=attr-script-async><a href=#attr-script-async>async</a></code> attribute and a <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute</dt>

<dd>The element must be added to the end of the <a href=#list-of-scripts-that-will-execute-asynchronously>list of
scripts that will execute asynchronously</a>.</dd>


<dt>If the element has an <code title=attr-script-async><a href=#attr-script-async>async</a></code> attribute but no <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute, and the <a href=#list-of-scripts-that-will-execute-asynchronously>list
of scripts that will execute asynchronously</a> is not
empty</dt>

<dd>The element must be added to the end of the <a href=#list-of-scripts-that-will-execute-asynchronously>list of
scripts that will execute asynchronously</a>.</dd>
parsing</a>.</dd>


<dt>If the element has a <code title=attr-script-src><a href=#attr-script-src>src</a></code>
attribute and has been flagged as
<a href=#parser-inserted>"parser-inserted"</a></dt>
attribute, and the element has been flagged as
<a href=#parser-inserted>"parser-inserted"</a>, and the element does not have an
<code title=attr-script-async><a href=#attr-script-async>async</a></code> attribute</dt>

<dd>The element is the <dfn id=pending-external-script>pending external script</dfn>. (There
can only be one such script at a time.)</dd>
@@ -12301,12 +12286,10 @@ people expect to have work and what is necessary.
the resource has been <a href=#fetch title=fetch>fetched</a> (defined
below) has been run.</p>

<p><dfn id=when-a-script-completes-loading>When a script completes loading</dfn>: If the
<code><a href=#script>script</a></code> element was added to one of the lists mentioned
above and the document is still being parsed, then the parser
handles it. Otherwise, the UA must run the following steps as the
<a href=#concept-task title=concept-task>task</a> that the <a href=#networking-task-source>networking
task source</a> places on the <a href=#task-queue>task queue</a>:</p>
<p><dfn id=when-a-script-completes-loading>When a script completes loading</dfn>: The UA must run the
following steps as the <a href=#concept-task title=concept-task>task</a> that
the <a href=#networking-task-source>networking task source</a> places on the <a href=#task-queue>task
queue</a>:</p>

<dl class=switch><dt>If the <code><a href=#script>script</a></code> element was added to the <dfn id=list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list
of scripts that will execute when the document has finished
@@ -12316,6 +12299,13 @@ people expect to have work and what is necessary.

<ol><li>

<p>If the script's <code>Document</code> is still being parsed,
then the parser handles it. Abort these steps.</p>

</li>

<li>

<p>If the <code><a href=#script>script</a></code> element is not the first element
in the list, then do nothing yet. Stop going through these
steps.</p>
@@ -12344,49 +12334,6 @@ people expect to have work and what is necessary.

</li>

</ol><p class=note>The scripts in the <a href=#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list of scripts that will
execute when the document has finished parsing</a> can also get
executed prematurely if the <code title=dom-innerHTML><a href=#dom-innerhtml>innerHTML</a></code> attribute is set on a node
in the document.</p>

</dd>

<dt>If the <code><a href=#script>script</a></code> element was added to the <dfn id=list-of-scripts-that-will-execute-asynchronously>list
of scripts that will execute asynchronously</dfn>:</dt>

<dd>

<ol><li>

<p>If the script is not the first element in the list, then do
nothing yet. Stop going through these steps.</p>

</li>

<li>

<p><a href=#executing-a-script-block title="executing a script block">Execute the script
block</a> (the first element in the list).</p>

</li>

<li>

<p>Remove the <code><a href=#script>script</a></code> element from the list
(i.e. shift out the first entry in the list).</p>

</li>

<li>

<p>If there are any more scripts in the list, and the element
now at the head of the list had no <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute when it was added
to the list, or had one, but its associated script has finished
loading, then jump back to step 2 to execute the script
associated with this element.</p>

</li>

</ol></dd>

<dt>If the <code><a href=#script>script</a></code> element was added to the <dfn id=list-of-scripts-that-will-execute-as-soon-as-possible>list
@@ -61192,13 +61139,7 @@ interface <dfn id=messageport>MessagePort</dfn> {
<p>Before each step of the tokenizer, the user agent must first
check the <a href=#parser-pause-flag>parser pause flag</a>. If it is true, then the
tokenizer must abort the processing of any nested invocations of the
tokenizer, yielding control back to the caller. If it is false, then
the user agent may then check to see if either one of the scripts in
the <a href=#list-of-scripts-that-will-execute-as-soon-as-possible>list of scripts that will execute as soon as
possible</a> or the first script in the <a href=#list-of-scripts-that-will-execute-asynchronously>list of scripts
that will execute asynchronously</a>, has <a href=#completed-loading>completed
loading</a>. If one has, then it must be <a href=#executing-a-script-block title="executing a
script block">executed</a> and removed from its list.</p>
tokenizer, yielding control back to the caller.</p>

<p>The tokenizer state machine consists of the states defined in the
following subsections.</p>
@@ -66214,25 +66155,20 @@ document.body.appendChild(text);

<p>First, the user agent must set the <a href=#current-document-readiness>current document
readiness</a> to "interactive" and the <a href=#insertion-point>insertion
point</a> to undefined.</p>
point</a> to undefined.</p> <!-- this also synchronously fires an
event -->

<p>Then, the user agent must then make a list of all the scripts
that are in the <a href=#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list of scripts that will execute when the
document has finished parsing</a>, the <a href=#list-of-scripts-that-will-execute-asynchronously>list of scripts that
will execute asynchronously</a>, and the <a href=#list-of-scripts-that-will-execute-as-soon-as-possible>list of scripts
document has finished parsing</a> and the <a href=#list-of-scripts-that-will-execute-as-soon-as-possible>list of scripts
that will execute as soon as possible</a>. This is the <dfn id=list-of-scripts-pending-after-the-parser-stopped>list
of scripts pending after the parser stopped</dfn>.</p>

<p>The rules for <a href=#when-a-script-completes-loading>when a script completes loading</a> start
applying (script execution is no longer managed by the parser).</p>

<p>If any of the scripts in the <a href=#list-of-scripts-that-will-execute-as-soon-as-possible>list of scripts that will
execute as soon as possible</a> have <a href=#completed-loading>completed
loading</a>, or if the <a href=#list-of-scripts-that-will-execute-asynchronously>list of scripts that will execute
asynchronously</a> is not empty and the first script in that list
has <a href=#completed-loading>completed loading</a>, then the user agent must act as
if those scripts just completed loading, following the rules given
for that in the <code><a href=#script>script</a></code> element definition.</p>
<p>The document is no longer being parsed, so the rules for
<a href=#when-a-script-completes-loading>when a script completes loading</a> for the <a href=#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list of
scripts that will execute when the document has finished
parsing</a> start applying (script execution for that list is no
longer managed by the parser).</p>

<p>If the <a href=#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list of scripts that will execute when the document
has finished parsing</a> is not empty, and the first item in this
@@ -66255,7 +66191,8 @@ document.body.appendChild(text);
run the following steps:</p>

<ol><li><a href=#queue-a-task>Queue a task</a> to set the <a href=#current-document-readiness>current document
readiness</a> to "complete".</li>
readiness</a> to "complete".</li> <!-- this also fires an event
synchronously during the task -->

<li>If the <code>Document</code> is in a <a href=#browsing-context>browsing
context</a>, then <a href=#queue-a-task>queue a task</a> to <a href=#fire-a-simple-event>fire a

0 comments on commit b7a9d94

Please sign in to comment.