You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-13Lines changed: 23 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -548,39 +548,49 @@ The META elements can be used to include name/value pairs describing properties
548
548
549
549
## Q. What does async and defer refer in script tag?
550
550
551
-
***Async**: Downloads the script file during HTML parsing and will pause the HTML parser to execute it when it has finished downloading.
551
+
**1. Async:**
552
552
553
-
***Defer**: Defer downloads the script file during HTML parsing and will only execute it after the HTML parser has completed. Not all browsers support this.
554
-
555
-
The async attribute is used to indicate to the browser that the script file can be executed asynchronously. The HTML parser does not need to pause at the point it reaches the script tag to fetch and execute, the execution can happen whenever the script becomes ready after being fetched in parallel with the document parsing.
556
-
557
-
The defer attribute tells the browser to only execute the script file once the HTML document has been fully parsed.
553
+
Downloads the script file during HTML parsing and will pause the HTML parser to execute it when it has finished downloading.
558
554
559
555
**Example:**
560
556
561
557
```html
562
-
<!--
563
-
Without async or defer, browser will run your script immediately,
564
-
before rendering the elements.
565
-
-->
566
-
<scriptsrc="myscript.js"></script>
567
-
568
-
569
558
<!--
570
559
With async (asynchronous), browser will continue to load the HTML
571
560
page and render it while the browser load and execute the script at the same time.
572
561
-->
573
562
<!-- Google Analytics is usually added like this -->
Defer downloads the script file during HTML parsing and will only execute it after the HTML parser has completed. Not all browsers support this.
569
+
570
+
**Example:**
576
571
572
+
```html
577
573
<!--
578
574
With defer, browser will run your script when the page finished parsing.
579
575
(not necessary finishing downloading all image files. This is good.)
580
576
-->
581
577
<scriptdefersrc="myscript.js"></script>
582
578
```
583
579
580
+
The async attribute is used to indicate to the browser that the script file can be executed asynchronously. The HTML parser does not need to pause at the point it reaches the script tag to fetch and execute, the execution can happen whenever the script becomes ready after being fetched in parallel with the document parsing.
581
+
582
+
The defer attribute tells the browser to only execute the script file once the HTML document has been fully parsed.
583
+
584
+
**Example:**
585
+
586
+
```html
587
+
<!--
588
+
Without async or defer, browser will run your script immediately,
0 commit comments