Created
October 13, 2017 21:24
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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