Skip to content

Commit 063ab6f

Browse files
committed
Update README.md
1 parent cff4640 commit 063ab6f

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -548,39 +548,49 @@ The META elements can be used to include name/value pairs describing properties
548548

549549
## Q. What does async and defer refer in script tag?
550550

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:**
552552

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.
558554

559555
**Example:**
560556

561557
```html
562-
<!--
563-
Without async or defer, browser will run your script immediately,
564-
before rendering the elements.
565-
-->
566-
<script src="myscript.js"></script>
567-
568-
569558
<!--
570559
With async (asynchronous), browser will continue to load the HTML
571560
page and render it while the browser load and execute the script at the same time.
572561
-->
573562
<!-- Google Analytics is usually added like this -->
574563
<script async src="https://google-analytics.com/analytics.js"></script>
564+
```
575565

566+
**2. Defer:**
567+
568+
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:**
576571

572+
```html
577573
<!--
578574
With defer, browser will run your script when the page finished parsing.
579575
(not necessary finishing downloading all image files. This is good.)
580576
-->
581577
<script defer src="myscript.js"></script>
582578
```
583579

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,
589+
before rendering the elements.
590+
-->
591+
<script src="myscript.js"></script>
592+
```
593+
584594
<div align="right">
585595
<b><a href="#">↥ back to top</a></b>
586596
</div>

0 commit comments

Comments
 (0)