Skip to content

Instantly share code, notes, and snippets.

@C-Rodg
Created October 13, 2017 21:24
Show Gist options
  • Save C-Rodg/4025e43a3502a2aa316149d68b776401 to your computer and use it in GitHub Desktop.
Save C-Rodg/4025e43a3502a2aa316149d68b776401 to your computer and use it in GitHub Desktop.
A quick snippet using Javascript's requestAnimationFrame to determine when the document is ready or a library is loaded.
const ready = () => {
// Example of checking if library is available
if ('jQuery' in window) {
return;
}
// Example of checking if document is loaded
if (document.body) {
// Do code here...
return;
}
// Call again if not found
window.requestAnimationFrame(ready);
};
window.requestAnimationFrame(ready);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment