Skip to content

Instantly share code, notes, and snippets.

@tobiasroeder
Created January 10, 2024 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobiasroeder/b3961ea5353ad34a3a13f257dcd5467d to your computer and use it in GitHub Desktop.
Save tobiasroeder/b3961ea5353ad34a3a13f257dcd5467d to your computer and use it in GitHub Desktop.
Run code even if it is side-loaded or too late to the party, and do not wait for an event that has already happened.
function main() {
console.info('Page ready...');
}
if (document.readyState === 'complete') {
main();
} else {
window.addEventListener('load', function() {
main();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment