jQuery notReady
Let's consider that your webpage needs to call jQuery stuff when the DOM is ready, by using this common syntax:
<div class="my-div"></div> <script> jQuery(document).ready(function($) { $('.my-div').jQueryStuff(); }) </script>
This code needs jQuery to be loaded first. This is a problem if you want, for performance issues, load it at the bottom of the page.
The jquery.notready
script solves it by declaring a fake jQuery
object that you can use everywhere on the page,
and that will be replaced by the real one when it is loaded.
Based on an article of Sam Affron.
Installation
The easiest method using bower:
bower install jquery.notready
Or you may manually install the jquery.notready.min.js
and jquery.ready.min.js
scripts wherever you want in your project.
Then you just have to call the first script in your <head>
:
<script src="src/jquery.notready.js"></script> </head>
And the second one next to your jQuery call, at the bottom of the page:
<script src="src/vendor/jquery/dist/jquery.min.js"></script> <script src="src/jquery.ready.js"></script>
Usage
Just make your usual jQuery calls on the page.
For now, the following syntaxes are supported:
jQuery(document).bind("ready", callback)
jQuery(document).ready(callback)
jQuery().ready(callback)
jQuery(callback)
Please note that $
is not supported to avoid compatibility issues.
Changelog
0.1
Initial version