It appears from network panel, when you load scripts through Modernizr.load, it doesn't actually blocks $(document).ready().
So theoretically, let's say that I add json2.js through Modernizr, and another developer tries to use JSON.parse in $(document).ready(), their script could actually break because of the race condition.
Would it be possible to remedy this without try to police all the code check-ins?
Modernizr is a JavaScript library that detects which HTML5 and CSS3 features your visitor's browser supports. In detecting feature support, it allows developers to test for some of the new technologies and then provide fallbacks for browsers that do not support them.
The ready() method is used to make a function available after the document is loaded. Whatever code you write inside the $(document ). ready() method will run once the page DOM is ready to execute JavaScript code.
jQuery $(document). ready() Equivalent in JavaScript This event fires when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.
I'd see it this way: Using Modernizr (and browser tests) to load Javascript files is a very general design decision everyone on your team needs to be aware of in any case.
However, you probably want to implement (if you haven't yet) some sort of initialization of your application, which should be the last thing to be run — after everything has been loaded. This initialization can then be executed in a yepnope callback, apparently even within a $(document).ready()
wrapper.
Yepnope states in this context in the "common gotchas":
Just because your script is done, doesn't mean the document is ready. Don't forget that you can use document ready callbacks inside of your yepnope callbacks. If you're toying with the DOM, we'd heavily encourage you to do so, because your test environment may act differently than your production server the speeds are dramatically different.
And for the sake of completeness:
Without checking them any further, here a couple of other ideas on how to deal with document.ready + Modernizr.load
: How can I use yepnope.js with $(document).ready() effectively? and https://stackoverflow.com/a/6767886/564721
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With