Last active
September 27, 2018 19:58
-
-
Save neodigm/1673a1881c2276c49e0dbe8b76af0bf6 to your computer and use it in GitHub Desktop.
JavaScript Lazy Load
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var fLazy = (function(doc){ | |
return { "init" : function( _bMobl ){ | |
var _aE = [].slice.call( doc.querySelectorAll( "[data-lz-src]" ) ); | |
_aE.filter( function( _e ){ | |
if( _bMobl ){ // isMobile | |
if( _e.dataset.lzM ){ // data-lz-m | |
_e.src = _e.dataset.lzSrc; | |
} | |
}else{ | |
_e.src = _e.dataset.lzSrc; | |
} | |
}); | |
} | |
} | |
})( document ); | |
// You then call fLazy.init(), on intersection, setTimeOut or first Click. |
I've updated so that it now can process a sub-set of images based on a isMobile switch. Also, I believe that the Lighthouse extension v3.2 is a bit more stable, so try that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am sharing a simple lazy loader that I wrote in JS. This works but at the time of this writing Google Lighthouse was pretty buggy in auditing lazy loads, so be patient.