Skip to content

Commit ad8e0c8

Browse files
authored
async vs defer js
1 parent 242c2f9 commit ad8e0c8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,18 @@ window.addEventListener('contextmenu', ()=>{
359359
return false // cancel default menu
360360
},false)
361361
```
362+
363+
364+
# In HTML5, you can tell the browser when to run your JavaScript code
365+
```javascript
366+
367+
//Without async or defer, browser will run your script immediately, before rendering the elements that's below your script tag.
368+
<script src="myscript.js"></script>
369+
370+
//With async (asynchronous), browser will continue to load the HTML page and render it while the browser load and execute the script at the same time.
371+
//Async is more useful when you really don't care when the script loads and nothing else that is user dependent depends upon that script loading.(for scripts likes Google analytics)
372+
<script async src="myscript.js"></script>
373+
374+
//With defer, browser will run your script when the page finished parsing. (not necessary finishing downloading all image files.
375+
<script defer src="myscript.js"></script>
376+
```

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy