본문 바로가기
JavaScript

[JavaScript] script async / defer 차이점

by ghan2 2024. 10. 9.
자바스크립트 공부 사이트 

https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint

 

Document: elementFromPoint() method - Web APIs | MDN

The elementFromPoint() method, available on the Document object, returns the topmost Element at the specified coordinates (relative to the viewport).

developer.mozilla.org

 

script async와 defer의 차이점

1. <head> 안에 <script>를 넣는 경우

2. <body>의 가장 끝에 <script>를 넣는 경우

3. <head> 안에서 <script async src="#"> 를 주는 경우

=> fetching, executing 작업을 비동기적으로 실행 (executing 시간에는 블락됨)

4. <head> 안에서 <script defer src="#"> 를 주는 경우

=> js파일을 먼저 fetching해두고 돔에 html이 모두 연결된 이후에 js를 실행시킨다.

 

use strict

순수 바닐라 자바스크립트를 쓸 때는 'use strict'; 를 적어주는 것이 좋다.

유연한 자바스크립트를 좀 더 엄격하게 관리해준다. (선언되지 않는 변수를 사용하는 등..)

 

 

 


https://www.youtube.com/watch?v=tJieVCgGzhs&list=PLv2d7VI9OotTVOL4QmPfvJWPJvkmv6h-2&index=2