Safely use .ready() before including jQuery
All credit goes to @collypops for his article Safely using .ready() before including jQuery.
PseudojQuery allows you to include jQuery code before including jQuery. This allows you to load jQuery at the bottom of your page to prevent render blocking.
Minified, the pseudojQuery-start and pseudojQuery-end files are only 209 bytes and 123 bytes respectively.
bower install pseudojQuery
If you are using Grunt, navigate to your pseudojQuery directory and run:
npm install
This will install the Node dependencies. Then run the default grunt task compile the minified files.
Or...
To use sudojQuery, place the sudojQuery-start.min.js file in the <head> section of your HTML, and place the pseudojQuery-end.min.js file after your inclusion of jQuery, and you're good to go:
<head>
...
<!-- sudojQuery start -->
<script src="pseudojQuery-start.min.js"></script>
</head>
<body>
<script>
// some jQuery code
$(document).ready(function() {
alert("Success!");
});
jQuery(document).ready(function() {
alert("Success!");
});
</script>
<!-- jQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<!-- sudojQuery end -->
<script src="pseudojQuery-end.min.js"></script>
</body>Your jQuery code must be contained within a document.ready function as shown above.
Released: 16th October 2015
- removing compiled minified files from master branch