defer attribute on a <script> tag specifies that the script is executed after the page has loaded.
This only works for external scripts.
defer attribute on a <script> element.
<script src="/tutorial/script-defer.js" defer> </script>
Here is the script file. It displays an alert box when executed.
alert("This alert is executed deferred.");
defer attribute specifies that the script file will execute after the page has finished loading.
This attribute only works with external scripts and only when src attribute is present.
External script files can be executed in the following 3 ways:
Here is when
defer support started for each browser:
Back to <script>