Describe the difference between `<script>`, `<script async>` and `<script defer>`

High
HTMLJAVASCRIPT

For normal <script>s, when a <script> tag is encountered, HTML parsing is blocked, the script is fetched and executed immediately. HTML parsing resumes after the script is executed.

async

In <script async>, the script will be fetched in parallel to HTML parsing and executed as soon as it is available (potentially before HTML parsing completes). Use async when the script is independent of any other scripts on the page, for example, analytics.

defer

In <script defer>, the script will be fetched in parallel to HTML parsing and executed when the documented has been parsed. If there are multiple of them, each deferred script is executed in the order they were encountered in the document.

If a script relies on a fully-parsed DOM, the defer attribute will be useful in ensuring that the HTML is fully parsed before executing. A deferred script must not contain document.write().

Notes

The async and defer attributes are ignored for scripts that have no src attribute.

References