So, I know the general order of when a script executes...
According to this defer
ed scripts are executed before the DOMContentLoaded
event gets fired, but do not block the page and subsequent scripts from loaded (unless they are also defered). Please correct me if I'm wrong here.
This seems like another way of including scripts and executing them after the DOM is available, so when should I use this over document.addEventListener('DOMContentLoaded', function(){...});
? And as of ES6, what is the best practice for executing/loading scripts after the DOM becomes available? I assume addEventListener
is preferred over jQuery's $(document).ready
or window.onload
(again, correct me if I'm wrong...), but where does defer
or other methods of loading scripts come into play?