The first way is by using the defer attribute of the script element. Here’s what it looks like:
<script src="myscript.js" defer></script>
When present, the defer attribute will cause the script to be executed once the page has finished parsing.
Another way to defer loading and execution of a script is the method recommended by Google. Google recommends putting the following code at the very bottom of your web page. To use it, you would replace the sample script name (here, myscript.js) with your own filename, of course.
<script src="myscript.js" async></script>
Like the defer attribute, the async attribute can only be used with external scripts (where the src attribute is used). When present, the async attribute will cause the script to be executed asynchronously with the rest of the page. In other words, the script will execute at the same time as the rest of the page.