htmlpreview / htmlpreview.github.com

HTML Preview for GitHub Repositories
htmlpreview.github.com
1.51k stars 303 forks source link

Javascript window load event fires inconsistently #126

Open lvlte opened 1 year ago

lvlte commented 1 year ago

I need some JS to run once all dependent resources have loaded, so I use the window load event , ie.

window.addEventListener('load', function(event) {
  console.log('window.load');
});

But for some reason it won't fire consistently, I would say the handler is executed 1 time out of 10.

If I use document.addEventListener('DOMContentLoaded', handler) though it works fine, but the script then runs too early, especially on htmlpreview where the css files seem to take a long time to load and execute (compared to the js files).