Two Modernizr tests in modernizr.load ()?

I need to check support for two elements before loading resources using yep / nope / modernizr.load (). How can you do this?

And when passing both tests, not one or the other, but both.

One is a custom test that I have already added and the other is an existing test.

+3


source to share


2 answers


Modernizr documentation has an answer for you:

Taken from the docs ...

Modernizr.load is small and simple, but it can do some pretty heavy lifting for you. Here's a slightly more complex example of using Modernizr.load when your scripts are based on more than one Modernizr test. A good technique is to combine multiple polyfills into one type of "oldbrowser" script so that you don't load too many scripts at the same time. This is how it might work:

Modernizr.load([
  {
    test : Modernizr.fontface && Modernizr.canvas && Modernizr.cssgradients,
    nope : ['presentational-polyfill.js', 'presentational.css']
  }
]);

      



So, as you can see, the answer is to simply put all the tests you need into a boolean expression.

I have simplified the example from the docs and in fact the examples given in the docs are more verbose, so go ahead and read them just as it might give you an even better way of doing what re after.

Hope it helps.

+2


source


@ Spudley's answer is great, but maybe more useful in some cases



Modernizr.load([
    {
      test:  Modernizr.input.autofocus || Modernizr.cssanimations,
    nope: 'jquery.js'
   },
   {
    test: Modernizr.input.autofocus,
    nope: 'autofocus.js'
   },
   {
     test: Modernizr.cssanimations,
     nope: 'animations.js'
   }
   ]);

      

+1


source







All Articles