5

My app includes Modernizr (concatenated with prefixfree) just before the closing <head> tag, and the rest of the js just before the closing <body> tag. 99.9% of the time this works fine, but sometimes I get Modernizr is not defined.

The code causing the error is:

if(!Modernizr.csscalc) {
  // do stuff
}

This error happens on real clients (I get notifications by email), so I don't have much more data than this error string. I also fail to reproduce it, even on same OS and browser.

I have no clue for what may be the cause of this sporadic error. Could you please direct me? Am I doing something wrong here?

2
  • 2
    The connection loading the modenizer file might time out. Since you haven't really shown any of your code, it's impossible to say if you do something wrong or not. The example you posted it definitely syntactically valid and will run assuming that Modernizr is defined (and not null). Since it seems to work in most cases, I guess your code is correct. Apr 6, 2014 at 7:07
  • @FelixKling Good point about the timeout! I haven't thought about it, and it fits my case.. I'll handle this in my code and see if the error occurs again. Thank you!
    – Tzach
    Apr 6, 2014 at 7:17

1 Answer 1

1

There could be a number of different reasons why this is happening.

As Felix mentioned, the file itself may not have loaded (you should have file timeouts tracked on your analytics setup as well, if you don't already).

Another possibility is that Modernizr itself had problems and threw an error due to issues with a specific browser (can easily be true with older and cutting edge versions of it). First thing would be to make sure you are running the most up to date version of the library, second would be to report any pattern you see upstream to Modernizr's github page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.