Skip to content

Instantly share code, notes, and snippets.

@nmurzin
Created August 26, 2016 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmurzin/19834d008ee8ff3cf3a731f25deed70d to your computer and use it in GitHub Desktop.
Save nmurzin/19834d008ee8ff3cf3a731f25deed70d to your computer and use it in GitHub Desktop.
How to transfer jquery to bottom of the page
<head>
<script>
// Fallback code for the jQuery inline scripts on pages:
if (window.jQuery === undefined) {
window.jQueryReadyHandlers = [];
window.$ = window.jQuery = function (callback) {
window.jQueryReadyHandlers.push(callback);
return window.$;
};
window.$.ready = window.$;
}
</script>
<!-- ...some head items -->
</head>
<body>
<!-- ...some page content -->
<script>
// some onReady-handlers
$(function(){
console.log('First callback');
});
jQuery(document).ready(function(){
console.log('Second callback');
});
</script>
<!-- ...some page content -->
<script src="//js/jquery.min.js"></script>
<script>
jQuery(window).load(function(){
if(window.jQueryReadyHandlers) {
$.each(window.jQueryReadyHandlers, function(index,func){
$(func);
});
}
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment