diff options
Diffstat (limited to 'files/zh-tw/web/html/element/script/index.html')
-rw-r--r-- | files/zh-tw/web/html/element/script/index.html | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/files/zh-tw/web/html/element/script/index.html b/files/zh-tw/web/html/element/script/index.html index 575be45b12..3b78b80a41 100644 --- a/files/zh-tw/web/html/element/script/index.html +++ b/files/zh-tw/web/html/element/script/index.html @@ -59,16 +59,22 @@ translation_of: Web/HTML/Element/script <dt>{{htmlattrdef("crossorigin")}}</dt> <dd>針對沒有通過標準 <a href="/zh-TW/docs/HTTP_access_control">CORS</a> 的一般 <code>script</code> 元素,會把最少的資訊傳給 {{domxref('GlobalEventHandlers.onerror', 'window.onerror')}}。若要允許另一個域名站點的靜態內容,列出錯誤訊息,請使用此屬性。請參見 <a href="/zh-TW/docs/Web/HTML/CORS_settings_attributes">CORS settings attributes</a> 以以取得對其有效參數的,更具描述性的解釋。</dd> <dt>{{htmlattrdef("defer")}}</dt> - <dd>This Boolean attribute is set to indicate to a browser that the script is meant to be executed after the document has been parsed, but before firing {{event("DOMContentLoaded")}}.</dd> - <dd>Scripts with the defer attribute will prevent the DOMContentLoaded event from firing until the script has loaded and finished evaluating.</dd> + <dd>設置此 Boolean attribute 是為了指示瀏覽器, script 應在 document 解析後,但在 firing {{event("DOMContentLoaded")}} 之前被執行。</dd> + <dd>具有 <code>defer</code> 屬性的 scripts 將阻止觸發<code>DOMContentLoaded</code> 事件,直到 scripts load 完成並且 finished evaluating。</dd> </dl> <div class="warning"> <p>如果沒有 <code>src</code> 屬性的話,就不能用這個屬性(例如行內腳本):在這種情況下,它將失去作用。</p> + +<p>The <code>defer</code> attribute has no effect on <a href="https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules">module scripts </a>— they defer by default.</p> </div> <dl> - <dd>To achieve a similar effect for dynamically inserted scripts use <code>async=false</code> instead. Scripts with the <code>defer</code> attribute will execute in the order in which they appear in the document.</dd> + <dd> + <p>Scripts with the <code>defer</code> attribute will execute in the order in which they appear in the document.</p> + + <p>This attribute allows the elimination of <strong>parser-blocking JavaScript</strong> where the browser would have to load and evaluate scripts before continuing to parse. <code>async</code> has a similar effect in this case.</p> + </dd> <dt>{{htmlattrdef("integrity")}}</dt> <dd>This attribute contains inline metadata that a user agent can use to verify that a fetched resource has been delivered free of unexpected manipulation. See <a href="/zh-TW/docs/Web/Security/Subresource_Integrity">Subresource Integrity</a>.</dd> <dt>{{htmlattrdef("nomodule")}}</dt> @@ -124,7 +130,7 @@ translation_of: Web/HTML/Element/script <p>以下示例展示如何在 HTML4 與 HTML5 使用 <code><script></code> 屬性。</p> -<pre class="brush: html"><!-- HTML4 與 (x)HTML --> +<pre class="brush: html notranslate"><!-- HTML4 與 (x)HTML --> <script type="text/javascript" src="javascript.js"></script> <!-- HTML5 --> @@ -135,7 +141,7 @@ translation_of: Web/HTML/Element/script <p>有針對 type 屬性支援 module(模組)的瀏覽器,會忽略 nomodule 屬性的程式碼。這能讓那些不支援模組的瀏覽器,提供替代的使用方法。</p> -<pre class="brush: js"><script type="module" src="main.mjs"></script> +<pre class="brush: js notranslate"><script type="module" src="main.mjs"></script> <script nomodule src="fallback.js"></script></pre> <h2 id="規範">規範</h2> @@ -157,12 +163,12 @@ translation_of: Web/HTML/Element/script <tr> <td>{{SpecName('HTML5 W3C', 'scripting-1.html#script', '<script>')}}</td> <td>{{Spec2('HTML5 W3C')}}</td> - <td> </td> + <td></td> </tr> <tr> <td>{{SpecName('HTML4.01', 'interact/scripts.html#h-18.2.1', '<script>')}}</td> <td>{{Spec2('HTML4.01')}}</td> - <td> </td> + <td></td> </tr> <tr> <td>{{SpecName('Subresource Integrity', '#htmlscriptelement', '<script>')}}</td> |