Understanding async vs defer in <script> tags
When including JavaScript in HTML using the <script> tag, the async and defer attributes control how and when the script is loaded and executed relative to HTML parsing.
async:
defer:
In short: Use async for independent scripts where execution order doesn’t matter, and defer for scripts that need the DOM fully loaded and/or must execute in a specific order.