I have something along the lines of the following code where I bind a window onload inside a closure. The window onload only seems to fire randomly or when the page takes a long time to load
$(() => {
console.log('test');
// code that needs to run when document is ready
window.onload = () => {
console.log('test 1');
// need this code to use some variables set in code above but only fire when all images have loaded so offsets are correct
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Why doesn't the onload fire every time the page loads?