Created
September 27, 2016 13:16
-
-
Save JacobLett/914c7b6a893def32ed8dfc8769254c95 to your computer and use it in GitHub Desktop.
defer after jquery loaded - jquery code before jquery 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
<script> | |
if ( ! window.deferAfterjQueryLoaded ) { | |
window.deferAfterjQueryLoaded = []; | |
Object.defineProperty(window, "$", { | |
set: function(value) { | |
window.setTimeout(function() { | |
$.each(window.deferAfterjQueryLoaded, function(index, fn) { | |
fn(); | |
}); | |
}, 0); | |
Object.defineProperty(window, "$", { value: value }); | |
}, | |
configurable: true | |
}); | |
} | |
window.deferAfterjQueryLoaded.push(function() { | |
//... some code that needs to be run | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/8298430/handling-code-which-relies-on-jquery-before-jquery-is-loaded/25636162