script 要素
4.3.1 script 要素
- カテゴリー
- メタデータ・コンテンツ
- フロー・コンテンツ
- フレージング・コンテンツ
- この要素を使うことができるコンテキスト:
- メタデータ・コンテンツが期待される場所
- フレージング・コンテンツが期待される場所
- コンテンツモデル:
src属性がなければ、type属性の値に依存する。ただし、スクリプト・コンテンツ制限に一致しなければならない。src属性があれば、この要素は、空か、スクリプト・コンテンツ制限に一致するスクリプト説明文のみを含むかの、いずれかでなければいけません。- コンテンツ属性:
- グローバル属性
srcasyncdefertypecharset- DOMインタフェース:
-
interface HTMLScriptElement : HTMLElement { attribute DOMString src; attribute boolean async; attribute boolean defer; attribute DOMString type; attribute DOMString charset; attribute DOMString text; };
script 要素は、ウェブ制作者がドキュメントに動的なスクリプトやデータブロックを含めることができるようにします。この要素は、ユーザーに対するコンテンツを表しません。
動的スクリプトを入れるために使う場合、インラインでスクリプトを組み込むか、または、src 属性を使って外部ファイルからスクリプトをインポートすることができます。スクリプト言語が "text/javascript" に相当するものでない場合、下記の通り、type 属性は必須です。どんな言語が使われるにしても、script 要素のコンテンツは、その言語仕様の要件に適合しなければいけません。
データ・ブロックを入れるために使う場合(スクリプトとは対照的ですが)、そのデータはインラインで組み込まなければいけません。そして、type 属性を使ってデータのフォーマットを指定しなければいけません。この場合、src 属性を指定してはいけません。そして、script 要素のコンテンツは、採用フォーマットに定義された要件に適合しなければいけません。
type 属性は、スクリプトの言語やデータのフォーマットを指定します。この属性が存在すれば、その値は妥当な MIME タイプでなければいけません。charset パラメータを指定してはいけません。デフォルトは "text/javascript" です。この属性がない場合に使われます。
src 属性は、指定する場合、利用する外部スクリプトのリソースのアドレスとなります。この属性値は、type 属性が存在するなら、それによって指定されたタイプの、存在しなければ、"text/javascript" タイプのスクリプトのリソースを識別するスペースで潜在的に囲まれた空でない妥当な URLでなければいけません。もし、そのタイプがスクリプト言語を指し、そのリソースがその言語仕様の要件に適合しているなら、そのリソースは指定タイプのリソースになります。
charset 属性は、外部スクリプト・リソースの文字エンコーディングを指定します。この属性は、src 属性がない場合は、指定してはいけません。もしこの属性がセットされた場合、その値は妥当な文字エンコーディング名でなければならず、そのエンコーディングに対する推奨 MIME 名に一致していなければいけません。大文字・小文字は区別されません。そして、外部ファイルの Content-Type メタデータの charset パラメータがあれば、そのエンコーディングに一致しなければいけません。 [IANACHARSET]
async と defer 属性は、どのようにスクリプトを実行すべきかを指し示す論理属性です。defer と async 属性は、src 属性が存在しない場合は、指定してはいけません。
これらの属性を使うと選択しうるモードが 3 つ考えられます。async 属性があれば、スクリプトは利用可能になった時点で非同期に実行されます。async 属性がなく、defer 属性があれば、スクリプトはページのパースが終了したときに実行されます。どちらの属性もなければ、ユーザーエージェントがページをパースする前に、即座にスクリプトが取り出され実行されます。
これらの属性の正確な処理の詳細は、主に歴史的な理由から、やや重要であり、HTML のいろいろな観点を巻き込んでいます。実装の要件は、それゆえに、やむを得ず、この仕様の全体にわたって散らばっています。下記(このセクション)のアルゴリズムは、この処理の中核を説明しています。しかし、これらのアルゴリズムは、HTML や 外部コンテンツや XML における script の start と end タグに対するパース規則、document.write() メソッドの規則、スクリプティング のハンドリングなどによって、参照されたり、参照したりします。
defer 属性は、たとえ async 属性が指定されていても、指定することができます。この場合、defer しかサポートしない(async をサポートしない)古いウェブブラウザーは、デフォルトである同期ブロッキング動作の代わりに、defer 挙動にフォールバックすることになります。
動的に src, type, charset, async, defer 属性を変更しても、直接的には何も起こりません。これらの属性は、後述しますが、ある特定の時にしか使われません。
A script element has several associated pieces of
state.
The first is a flag indicating whether or not the script block
has been "already started". Initially, script elements must have this flag unset (script
blocks, when created, are not "already started"). When a script element is cloned, the "already started" flag, if
set, must be propagated to the clone when it is created.
The second is a flag indicating whether the element was "parser-inserted". Initially, script elements must have this flag unset. It is set by the HTML
parser and the XML parser on script elements they insert and affects the processing of those
elements.
The third is a flag indicating whether the element will "force-async". Initially, script elements
must have this flag set. It is unset by the HTML parser and the XML parser on script elements they
insert. In addition, whenever a script element whose "force-async" flag is set has a async content attribute added, the
element's "force-async" flag must be unset.
The fourth is a flag indicating whether or not the script block is "ready to be parser-executed". Initially, script elements must have this flag unset (script
blocks, when created, are not "ready to be parser-executed"). This
flag is used only for elements that are also "parser-inserted", to let the parser know when to
execute the script.
The last few pieces of state are the script block's
type, the script block's character
encoding, and the script block's fallback
character encoding. They are determined when the script
is prepared, based on the attributes on the element at that time,
and the Document of the script element.
When a script element that is not marked as being "parser-inserted" experiences one of the events listed
in the following list, the user agent must synchronously prepare the script element:
- The
scriptelement gets inserted into a document. - The
scriptelement is in aDocumentand its child nodes are changed. - The
scriptelement is in aDocumentand has asrcattribute set where previously the element had no such attribute.
To prepare a script, the user agent must act as follows:
-
If the
scriptelement is marked as having "already started", then the user agent must abort these steps at this point. The script is not executed. -
If the element has its "parser-inserted" flag set, then set was-parser-inserted to true and unset the element's "parser-inserted" flag. Otherwise, set was-parser-inserted to false.
This is done so that if parser-inserted
scriptelements fail to run when the parser tries to run them, e.g. because they are empty or specify an unsupported scripting language, another script can later mutate them and cause them to run again. -
If was-parser-inserted is true and the element does not have an
asyncattribute, then set the element's "force-async" flag to true.This is done so that if a parser-inserted
scriptelement fails to run when the parser tries to run it, but it is later executed after a script dynamically updates it, it will execute asynchronously even if theasyncattribute isn't set. -
If the element has no
srcattribute, and its child nodes, if any, consist only of comment nodes and empty text nodes, then the user agent must abort these steps at this point. The script is not executed. -
If the element is not in a
Document, then the user agent must abort these steps at this point. The script is not executed. -
If either:
- the
scriptelement has atypeattribute and its value is the empty string, or - the
scriptelement has notypeattribute but it has alanguageattribute and that attribute's value is the empty string, or - the
scriptelement has neither atypeattribute nor alanguageattribute, then
...let the script block's type for this
scriptelement be "text/javascript".Otherwise, if the
scriptelement has atypeattribute, let the script block's type for thisscriptelement be the value of that attribute with any leading or trailing sequences of space characters removed.Otherwise, the element has a non-empty
languageattribute; let the script block's type for thisscriptelement be the concatenation of the string "text/" followed by the value of thelanguageattribute.The
languageattribute is never conforming, and is always ignored if there is atypeattribute present. - the
-
If the user agent does not support the scripting language given by the script block's type for this
scriptelement, then the user agent must abort these steps at this point. The script is not executed. -
If was-parser-inserted is true, then flag the element as "parser-inserted" again, and set the element's "force-async" flag to false.
-
The user agent must set the element's "already started" flag.
The state of the element at this moment is later used to determine the script source.
-
If the element is flagged as "parser-inserted", but the element's
Documentis not theDocumentof the parser that created the element, then abort these steps. -
If scripting is disabled for the
scriptelement, then the user agent must abort these steps at this point. The script is not executed.The definition of scripting is disabled means that, amongst others, the following scripts will not execute: scripts in
XMLHttpRequest'sresponseXMLdocuments, scripts inDOMParser-created documents, scripts in documents created byXSLTProcessor'stransformToDocumentfeature, and scripts that are first inserted by a script into aDocumentthat was created using thecreateDocument()API. [XHR] [DOMPARSER] [DOMCORE] -
If the
scriptelement has aneventattribute and aforattribute, then run these substeps:-
Let for be the value of the
forattribute. -
Let event be the value of the
eventattribute. -
Strip leading and trailing whitespace from event and for.
-
If for is not an ASCII case-insensitive match for the string "
window", then the user agent must abort these steps at this point. The script is not executed. -
If event is not an ASCII case-insensitive match for either the string "
onload" or the string "onload()", then the user agent must abort these steps at this point. The script is not executed.
-
-
If the
scriptelement has acharsetattribute, then let the script block's character encoding for thisscriptelement be the encoding given by thecharsetattribute.Otherwise, let the script block's fallback character encoding for this
scriptelement be the same as the encoding of the document itself.Only one of these two pieces of state is set.
-
If the element has a
srcattribute whose value is not the empty string, then the value of that attribute must be resolved relative to the element, and if that is successful, the specified resource must then be fetched, from the origin of the element'sDocument.If the
srcattribute's value is the empty string or if it could not be resolved, then the user agent must queue a task to fire a simple event namederrorat the element, and abort these steps.For historical reasons, if the URL is a
javascript:URL, then the user agent must not, despite the requirements in the definition of the fetching algorithm, actually execute the script in the URL; instead the user agent must act as if it had received an empty HTTP 400 response.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
srcattribute is dynamically changed, then the user agent will not execute the script, and the fetching process will have been effectively wasted. -
Then, the first of the following options that describes the situation must be followed:
- If the element has a
srcattribute, and the element has adeferattribute, and the element has been flagged as "parser-inserted", and the element does not have anasyncattribute -
The element must be added to the end of the list of scripts that will execute when the document has finished parsing associated with the
Documentof the parser that created the element.The task that the networking task source places on the task queue once the fetching algorithm has completed must set the element's "ready to be parser-executed" flag. The parser will handle executing the script.
- If the element has a
srcattribute, and the element has been flagged as "parser-inserted", and the element does not have anasyncattribute -
The element is the pending parsing-blocking script of the
Documentof the parser that created the element. (There can only be one such script perDocumentat a time.)The task that the networking task source places on the task queue once the fetching algorithm has completed must set the element's "ready to be parser-executed" flag. The parser will handle executing the script.
- If the element does not
have a
srcattribute, and the element has been flagged as "parser-inserted", and theDocumentof the HTML parser or XML parser that created thescriptelement has a style sheet that is blocking scripts -
The element is the pending parsing-blocking script of the
Documentof the parser that created the element. (There can only be one such script perDocumentat a time.)Set the element's "ready to be parser-executed" flag. The parser will handle executing the script.
- If the element has a
srcattribute, does not have anasyncattribute, and does not have the "force-async" flag set -
The element must be added to the end of the list of scripts that will execute in order as soon as possible associated with the
Documentof thescriptelement at the time the prepare a script algorithm started.The task that the networking task source places on the task queue once the fetching algorithm has completed must run the following steps:
-
If the element is not now the first element in the list of scripts that will execute in order as soon as possible to which it was added above, then mark the element as ready but abort these steps without executing the script yet.
-
Execution: Execute the script block corresponding to the first script element in this list of scripts that will execute in order as soon as possible.
-
Remove the first element from this list of scripts that will execute in order as soon as possible.
-
If this list of scripts that will execute in order as soon as possible is still not empty and the first entry has already been marked as ready, then jump back to the step labeled execution.
-
- If the element has a
srcattribute -
The element must be added to the set of scripts that will execute as soon as possible of the
Documentof thescriptelement at the time the prepare a script algorithm started.The task that the networking task source places on the task queue once the fetching algorithm has completed must execute the script block and then remove the element from the set of scripts that will execute as soon as possible.
- Otherwise
- The user agent must immediately execute the script block, even if other scripts are already executing.
- If the element has a
Fetching an external script must delay the load event of the element's document until the task that is queued by the networking task source once the resource has been fetched (defined above) has been run.
The pending parsing-blocking script of a Document is used by the Document's
parser(s).
If a script element that blocks a
parser gets moved to another Document before it would
normally have stopped blocking that parser, it nonetheless continues
blocking that parser until the condition that causes it to be
blocking the parser no longer applies (e.g. if the script is a pending parsing-blocking script because there was a style sheet that is blocking scripts when it was
parsed, but then the script is moved to another Document before the style sheet loads, the script still
blocks the parser until the style sheets are all loaded, at which
time the script executes and the parser is unblocked).
When the user agent is required to execute a script block, it must run the following steps:
-
If the element is flagged as "parser-inserted", but the element's
Documentis not theDocumentof the parser that created the element, then abort these steps. -
Jump to the appropriate set of steps from the list below:
- If the load resulted in an error (for example a DNS error, or an HTTP 404 error)
-
Executing the script block must just consist of firing a simple event named
errorat the element. - If the load was successful
-
Executing the script block must consist of running the following steps. For the purposes of these steps, the script is considered to be from an external file if, while the prepare a script algorithm above was running for this script, the
scriptelement had asrcattribute specified.-
Initialize the script block's source as follows:
- If the script is from an external file and the script block's type is a text-based language
-
The contents of that file, interpreted as string of Unicode characters, are the script source.
To obtain the string of Unicode characters, the user agent run the following steps:
-
If the resource's Content Type metadata, if any, specifies a character encoding, and the user agent supports that encoding, then let character encoding be that encoding, and jump to the bottom step in this series of steps.
-
If the algorithm above set the script block's character encoding, then let character encoding be that encoding, and jump to the bottom step in this series of steps.
-
For each of the rows in the following table, starting with the first one and going down, if the file has as many or more bytes available than the number of bytes in the first column, and the first bytes of the file match the bytes given in the first column, then set character encoding to the encoding given in the cell in the second column of that row, and jump to the bottom step in this series of steps:
Bytes in Hexadecimal Encoding FE FF Big-endian UTF-16 FF FE Little-endian UTF-16 EF BB BF UTF-8 This step looks for Unicode Byte Order Marks (BOMs).
-
Let character encoding be the script block's fallback character encoding.
-
Convert the file to Unicode using character encoding, following the rules for doing so given by the specification for the script block's type.
-
- If the script is from an external file and the script block's type is an XML-based language
-
The external file is the script source. When it is later executed, it must be interpreted in a manner consistent with the specification defining the language given by the script block's type.
- If the script is inline and the script block's type is a text-based language
-
The value of the
textIDL attribute at the time the element's "already started" flag was last set is the script source. - If the script is inline and the script block's type is an XML-based language
-
The child nodes of the
scriptelement at the time the element's "already started" flag was last set are the script source.
-
If the script is from an external file, then increment the ignore-destructive-writes counter of the
scriptelement'sDocument. Let neutralized doc be thatDocument. -
Create a script from the
scriptelement node, using the script block's source and the script block's type.This is where the script is compiled and actually executed.
-
Decrement the ignore-destructive-writes counter of neutralized doc, if it was incremented in the earlier step.
-
If the script is from an external file, fire a simple event named
loadat thescriptelement.Otherwise, the script is internal; queue a task to fire a simple event named
loadat thescriptelement.
-
The IDL attributes src, type, charset, and defer, each must reflect the respective content attributes of the same
name.
The async IDL
attribute controls whether the element will execute asynchronously
or not. If the element's "force-async" flag is set,
then, on getting, the async IDL attribute must return true, and on setting, the "force-async" flag must first be unset, and then the
content attribute must be removed if the IDL attribute's new value
is false, and must be set to the empty string if the IDL attribute's
new value is true. If the element's "force-async" flag
is not set, the IDL attribute must reflect the async content attribute.
IDL 属性 text は、script 要素の直下の子要素となるすべてのテキストノードのコンテンツをツリー順に連結したものを返さなければいけません(コメントや要素は無視されます)。値が指定されたら、textContent IDL 属性と同じように動作しなければいけません。
document.write() メソッドを使って挿入された場合は、script 要素は(通常は同期的に)実行します。しかし、innerHTML や outerHTML 属性を使って挿入された場合は、何も実行しません。
この例では、ふたつの script 要素が使われています。一方は外部スクリプトを組み込み、もう一方はいくらかのデータを含んでいます。
<script src="game-engine.js"></script> <script type="text/x-game-map"> ........U.........e o............A....e .....A.....AAA....e .A..AAA...AAAAA...e </script>
この場合のデータは、スクリプトがビデオゲームの地図を生成するために使うかもしれません。しかし、そのデータを、そのように使わなければいけないというわけではありません。恐らく、その地図データは、実際にはページのマークアップの他の部分に組み込まれているかもしれません。そして、ここにあるデータブロックは、そのゲーム地図内の特定の特徴を探すユーザーを助けるために、サイトの検索エンジンによって使われるだけなのかもしれません。
次のサンプルは、後にドキュメントの別の箇所で使われる関数を定義するために、どうやって script 要素を使うのかを示しています。また、ドキュメントがパースされている最中にスクリプトを呼び出すために、script 要素をどうやって使うのかを示しています。この例では、フォームの出力を初期化しています。
<script>
function calculate(form) {
var price = 52000;
if (form.elements.brakes.checked)
price += 1000;
if (form.elements.radio.checked)
price += 2500;
if (form.elements.turbo.checked)
price += 5000;
if (form.elements.sticker.checked)
price += 250;
form.elements.result.value = price;
}
</script>
<form name="pricecalc" onsubmit="return false" onchange="calculate(this)">
<fieldset>
<legend>Work out the price of your car</legend>
<p>Base cost: £52000.</p>
<p>Select additional options:</p>
<ul>
<li><label><input type=checkbox name=brakes> Ceramic brakes (£1000)</label></li>
<li><label><input type=checkbox name=radio> Satellite radio (£2500)</label></li>
<li><label><input type=checkbox name=turbo> Turbo charger (£5000)</label></li>
<li><label><input type=checkbox name=sticker> "XZ" sticker (£250)</label></li>
</ul>
<p>Total: £<output name=result></output></p>
</fieldset>
<script>
calculate(document.forms.pricecalc);
</script>
</form>
4.3.1.1 スクリプティング言語
スクリプト・ブロックのタイプが、ユーザーエージェントが実装しているスクリプト言語の MIME タイプ文字列に一致するなら、ユーザーエージェントはスクリプト言語をサポートしているといいます。大文字・小文字は区別しません。
以下に、MIME タイプとそれが参照する言語をいくつか挙げます:
- "
application/ecmascript" - "
application/javascript" - "
application/x-ecmascript" - "
application/x-javascript" - "
text/ecmascript" - "
text/javascript" - "
text/javascript1.0" - "
text/javascript1.1" - "
text/javascript1.2" - "
text/javascript1.3" - "
text/javascript1.4" - "
text/javascript1.5" - "
text/jscript" - "
text/livescript" - "
text/x-ecmascript" - "
text/x-javascript" - JavaScript. [ECMA262]
- "
text/javascript;e4x=1" - JavaScript with ECMAScript for XML. [ECMA357]
ユーザーエージェントは、他の MIME タイプや言語をサポートすることができます。
サポートする言語かどうかをタイプから決定するとき、ユーザーエージェントは、未知の MIME パラメータを無視してはいけません。未知のパラメータ付きのタイプは、未対応であると見なさなければいけません。charset パラメータは、ここでの MIME タイプ の比較という意味においては、未知のパラメータとして扱われなければいけません。
4.3.1.2 script 要素のコンテンツの制限
script 要素の textContent は、次の ABNF にある script プロダクション、および、Unicode の文字セットに一致しなければいけません。[ABNF]
script = data1 *( escape [ script-start data3 ] "-->" data1 ) [ escape ] escape = "<!--" data2 *( script-start data3 script-end data2 ) data1 = <any string that doesn't contain a substring that matches not-data1> not-data1 = "<!--" data2 = <any string that doesn't contain a substring that matches not-data2> not-data2 = script-start / "-->" data3 = <any string that doesn't contain a substring that matches not-data3> not-data3 = script-end / "-->" script-start = lt s c r i p t tag-end script-end = lt slash s c r i p t tag-end lt = %x003C ; U+003C LESS-THAN SIGN character (<) slash = %x002F ; U+002F SOLIDUS character (/) s = %x0053 ; U+0053 LATIN CAPITAL LETTER S s =/ %x0073 ; U+0073 LATIN SMALL LETTER S c = %x0043 ; U+0043 LATIN CAPITAL LETTER C c =/ %x0063 ; U+0063 LATIN SMALL LETTER C r = %x0052 ; U+0052 LATIN CAPITAL LETTER R r =/ %x0072 ; U+0072 LATIN SMALL LETTER R i = %x0049 ; U+0049 LATIN CAPITAL LETTER I i =/ %x0069 ; U+0069 LATIN SMALL LETTER I p = %x0050 ; U+0050 LATIN CAPITAL LETTER P p =/ %x0070 ; U+0070 LATIN SMALL LETTER P t = %x0054 ; U+0054 LATIN CAPITAL LETTER T t =/ %x0074 ; U+0074 LATIN SMALL LETTER T tag-end = %x0009 ; U+0009 CHARACTER TABULATION (tab) tag-end =/ %x000A ; U+000A LINE FEED (LF) tag-end =/ %x000C ; U+000C FORM FEED (FF) tag-end =/ %x0020 ; U+0020 SPACE tag-end =/ %x002F ; U+002F SOLIDUS (/) tag-end =/ %x003E ; U+003E GREATER-THAN SIGN (>)
script 要素が script
documentation を含むときは、次のセクションで説明するとおり、さらに追加の制限が、この要素のコンテンツに課せられます。
4.3.1.3 外部スクリプト用のインライン説明文
script 要素の src 属性が指定されたら、script 要素のコンテンツは、もしあれば、要素のコンテンツから引き出される text IDL 属性の値が、次の ABNF の documentation プロダクション、および、Unicode の文字セットに一致するようにしなければいけません。[ABNF]
documentation = *( *( space / tab / comment ) [ line-comment ] newline )
comment = slash star *( not-star / star not-slash ) 1*star slash
line-comment = slash slash *not-newline
; characters
tab = %x0009 ; U+0009 CHARACTER TABULATION (tab)
newline = %x000A ; U+000A LINE FEED (LF)
space = %x0020 ; U+0020 SPACE
star = %x002A ; U+002A ASTERISK (*)
slash = %x002F ; U+002F SOLIDUS (/)
not-newline = %x0000-0009 / %x000B-10FFFF
; a Unicode character other than U+000A LINE FEED (LF)
not-star = %x0000-0029 / %x002B-10FFFF
; a Unicode character other than U+002A ASTERISK (*)
not-slash = %x0000-002E / %x0030-10FFFF
; a Unicode character other than U+002F SOLIDUS (/)
これは、JavaScript コメントの中に要素のコンテンツを差し込むことに相当します。
この要件は、さらに、script 要素のコンテンツの構文における前段の制限が加わります。
これは、ウェブ制作者が、外部スクリプトファイルを参照すると同時に、そのドキュメントの中では、著作権情報や API 情報といった説明文を入れることができるようにしたものです。この構文は、src 属性も提供しているとはいえ、ウェブ制作者が誤って妥当なスクリプトのように見えるものを含めないよう、制約されます。
<script src="cool-effects.js"> // create new instances using: // var e = new Effect(); // start the effect using .play, stop using .stop: // e.play(); // e.stop(); </script>
4.3.1.4 script 要素と XSLT との相互作用
このセクションは非規定です。
本仕様は、XSLT が script 要素とどう作用し合うのか(実際には、XSLT 処理が stop parsing 手順をどのように呼び出すのか、ナビゲーション・アルゴリズムとどう作用し合うのか、イベント・ループに如何に合わせるのか)については定義しません。しかし、実際にはこれを定義している仕様がないため、ここでは、実装者向けに、既存の実装に基づいて、いくつかのガイドラインを示します:
-
XSLT 変形プログラムが
<?xml-stylesheet?>処理命令によって呼び出され、ブラウザーが直接的な DOM 変形を実装しているなら、XSLT プロセッサーによって生成されたscript要素は、"parser-inserted" とマークされる必要があります。そして、ドキュメント順に実行する必要があります(modulo scripts marked defer or async)。一方、変形は非同期に行われます。 -
XSLTProcessor.transformToDocument()メソッドは、ブラウジング・コンテキストにないDocumentに要素を追加します。そして、それに応じて、それらが生成するあらゆるscript要素は、スクリプト準備アルゴリズムにおいて、"already started" フラグ がセットされる必要があります。決して実行されることはありません(スクリプティングは無効です。)。そのようなscript要素は、なお、"parser-inserted" とマークされている必要があります。しかし、asyncIDL 属性はasyncコンテンツ属性が無いため false を返します。 -
XSLTProcessor.transformToFragment()メソッドは、document.createElementNS()を使って要素を生成することによって、手動で生成されたものと同等であるフラグメントを生成する必要があります。例えば、それは、"parser-inserted" ではなく、"already started" フラグを持たないscript要素を生成する必要があります。そうすることで、それらは、そのフラグメントがドキュメントに挿入されるときに実行することができます。
最初の 2 つの場合と最後の場合の間の大きな違いは、最初の 2 つは Document で動作するのに対し、最後のはフラグメントで動作するという点です。
※ 原文:http://www.w3.org/TR/2011/WD-html5-20110525/scripting-1.html#the-script-element