Skip to content

Instantly share code, notes, and snippets.

@JacobLett
Created September 27, 2016 13:16
Show Gist options
  • Save JacobLett/914c7b6a893def32ed8dfc8769254c95 to your computer and use it in GitHub Desktop.
Save JacobLett/914c7b6a893def32ed8dfc8769254c95 to your computer and use it in GitHub Desktop.
defer after jquery loaded - jquery code before jquery is loaded
<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