orenyakobi / lazy

Lightweight lazy loader for JS, CSS & LESS assets.
10 stars 1 forks source link

hack to listen for link onload event is calling requested page #2

Open philcruz opened 7 years ago

philcruz commented 7 years ago

Our application was getting errors going to certain pages that required url parameters. Tracked it down to this code in lazy

if(fileObj.ext === 'css'){
            //Hack for listening to link tag onload event
           var img = document.createElement('img');
           img.onerror = function(){
           if( typeof(clbk) !== 'undefined' ){
              clbk();
            }
       };
 img.src = '#';

I see that it using this technique http://www.backalleycoder.com/2011/03/20/link-tag-css-stylesheet-load-event/ to listen for css load events.

However, setting

img.src = '#'

is calling the requested page (again) and not the css. Should it be

img.src = fileObj.path

instead? Even if it's not causing errors it is calling the requested page unnecessarily.

orenyakobi commented 7 years ago

Hi Phil, Unfortunately I am not maintaining this project anymore. Please feel free to fork or create a pull request with your well tested suggestion.