Middle
Can you explain what the Vector class in Java is and what it is used for?
sobes.tech AI
Answer from AI
The async and defer attributes are used to control the loading and execution of external scripts in HTML:
-
async
- The script is loaded asynchronously in parallel with HTML parsing.
- Once the script is loaded, HTML parsing is interrupted, and the script is executed immediately.
- After execution, parsing continues.
- Scripts with async are executed in the order they are loaded, but the order is not guaranteed.
-
defer
- The script is loaded asynchronously in parallel with HTML parsing.
- Execution of the script is deferred until the entire HTML is fully parsed.
- Scripts with defer are executed in the order they are declared.
When is HTML parsing blocked?
- Without async/defer: parsing stops at
<script src=...>when the script is encountered, the script is loaded and executed, then parsing resumes. - With async: parsing is not blocked during loading but is blocked during script execution.
- With defer: parsing is not blocked during loading or execution; the script executes after the full parsing.
Use defer for scripts that depend on the DOM, and async for independent scripts, such as analytics.