How do I (or should I) extend the version of Modernizr.load () to preload images?

The idea is that the /something/index.html page loads. But, before I show it, its dependencies (css and images in this case) are preloaded.

Modernizr.load({ load: ['/something/styles.css', '/something/image1.jpg'], complete: showFile }); 

I looked in the Paul Irish "imagesLoaded" jQuery plug-in, but I prefer the ease of use of the bootloader that I already have. I know that YepNope (and Modernizr.load) are not developers as general preloaders, but I feel that this is the cleanest way to do this.

It would take any thoughts on how to implement image preloading in loading the Modernizr / YepNope script.

pg

+6
source share
1 answer

The yepnope documentation says preload! the prefix "should" work on some other mime types.

You may try

 Modernizr.load('preload!something/image1.jpg'); 

This work is for me.

Do not forget to add the prefix plugin (otherwise you will receive an error message when the js engine tries to execute the image):

 yepnope.addPrefix( 'preload', function ( resource ) { resource.noexec = true; return resource; }); 
+6
source

Source: https://habr.com/ru/post/895990/


All Articles