What is "defer"

Defer is a boolean attribute that when present specifies that the download of script will be performed asynchronously and will be executed only when the entire HTML rendering process is complete.

// Um script que não será executado até que a página seja carregada
<script src='meuscript.js' defer></script>

The attribute defer should only be used for external scripts, that is, only used when the attribute src is present. There are several ways an external script can be executed, some examples:

Undefined

<script src='meuscript.js'></script>

In this case, page rendering is blocked and it is expected that the script is loaded to then continue the rendering process, the execution of the script is done immediately after this process. This can increase the page load time so one of several recommendations is to keep the Javascript code at the end of the HTML document (before </body>).

With Defer

<script src="meuscript.js" defer></script> // com atributo defer

In this example of the script download is done asynchronously, without blocking the page rendering. Script execution takes place after the entire page has finished rendering.