Skip to content

Commit a65c2d8

Browse files
committed
added async vs defer
1 parent 9fd4992 commit a65c2d8

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

images/asyncVsDefer.jpg

33.7 KB
Loading

jsQuiz.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,14 @@ <h2>destroy button</h2>
205205
<p><strong>Answer:</strong> <a href="http://stackoverflow.com/a/1813267/1535443">stack overflow</a></p>
206206
</div>
207207
<div id="deferAsync">
208+
<h2>defer vs async</h2>
208209
<p><strong>Question:</strong> what is defer and async keyword does in a script tag</p>
209-
<p><strong>Answer:</strong></p>
210-
<p>ref: <a href="http://peter.sh/experiments/asynchronous-and-deferred-javascript-execution-explained/">JS script execution</a></p>
211-
<pre><code></code></pre>
210+
<p><strong>Answer:</strong> When HTML parser find a script tag.</p>
211+
<p><strong>normal</strong> when you have a plain script tag (no defer or async keyword), parser will pause parsing, script would be downloaded and exectuted. After that parsing resume.</p>
212+
<p><strong>defer</strong> defer keyword in the script tag will defer the execution of the script. Hence script will be executed when DOM is available. Its not recommeded to use defer when you dont have any src attribute in the script tag. Important point is, defer is not supported by all major major browsers.</p>
213+
<p><strong>async</strong> if possible, set the execution of the script, asynchronously. <code>async</code> keyword has no effect on inline script (script that has no src attribute)</p>
214+
<img src="images/asyncVsDefer.jpg" alt="">
215+
(src: <a href="http://peter.sh/experiments/asynchronous-and-deferred-javascript-execution-explained/">JS script execution</a>)
212216
</div>
213217
<div id="showAndTell">
214218
<h2>show and tell</h2>

0 commit comments

Comments
 (0)