6

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?

voidvector
  • 1,976
  • 2
  • 18
  • 19

1 Answers1

4

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

Community
  • 1
  • 1
polarblau
  • 17,649
  • 7
  • 63
  • 84
  • We ended up using Modernizr.load() for purely aesthetic shims. It is too painful to use for functional features. – voidvector Feb 29 '12 at 03:09