Created
April 24, 2018 08:14
-
-
Save tdshipley/6c09428edb887ae06fa4bfdc687de2e6 to your computer and use it in GitHub Desktop.
Wait for jQuery to load
This file contains 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
async function checkJquery(tries, tryLimit) { | |
console.log("Waiting for jQuery to Load"); | |
//1. Base Case - JQuery Loaded | |
if (window.jQuery) { | |
console.log("jQuery Loaded"); | |
return; | |
} | |
//2. Base Case - TryLimit Hit | |
if(parseInt(tries) > parseInt(tryLimit)) { | |
console.log("jQuery Failed to Load"); | |
return; | |
} | |
//3. Recursive Case | |
console.log("Could not find jQuery trying again. Try number " + tries + " of " + tryLimit); | |
// Wait a second. | |
var wait = ms => new Promise((r, j)=>setTimeout(r, ms)); | |
await wait(1000); | |
// Try again. | |
tries = parseInt(tries) + 1; | |
checkJquery(tries, tryLimit); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment