Expanding a bit on @Eruant's answer,
$(window).on('load', function() {
// your code here
});
Works very well with both async
and defer
while loading on scripts.
So you can import all scripts like this:
<script src="/js/script1.js" async defer></script>
<script src="/js/script2.js" async defer></script>
<script src="/js/script3.js" async defer></script>
Just make sure script1
doesn't call functions from script3
before $(window).on('load' ...
, make sure to call them inside window load
event.
More about async/defer here.