question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useSrcset=true should also set src as fallback on img tag

See original GitHub issue

In browsers that do not support srcset (e.g. IE11), ng-lazyload-image fails silently - onLoad is not even called with a false argument.

The proper way to handle this would be, in my opinion, to also set the src attribute to the largest image available in the srcset. This ensures that browsers without srcset support will at least load an image.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sapierenscommented, Apr 13, 2018

I agree and it should be quite easy to do, I guess we just need to change the following lines:

It would work with <picture>, but wouldn’t with <img> tags, since the srcset attribute has to be parsed to extract the correct image, e.g.:

<img srcset="img-320w.jpg 320w,
             img-480w.jpg 480w,
             img-800w.jpg 800w"
     sizes="(max-width: 320px) 280px,
            (max-width: 480px) 440px,
            800px">

Parsing this should be pretty easy (at least for selecting the largest image), but I’m not sure how much of an overhead it would add. But doing so would enable at least somewhat working lazy loading for browsers that don’t support srcset attribute. Maybe it’s worth looking into srcset polyfills to see how they’re doing their detection and parsing.

1reaction
tjoskarcommented, Apr 11, 2018

Hum… weird that onLoad is never called. It should be called with true even if srcset is not supported (since the image should be loaded anyway). ng-lazyload-image does not know if srcset is supported or not so it will assume it is (if useSrcset=true) and try to load it any way. It will then pass the path to the loaded image to the browser and then unsubscribes to all events.

I do however agree that ng-lazyload-image should check if srcset is supported but I’m not sure how. The only way I know is to use CSS.supports but that is not supported in IE 🤦‍♂️.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inputting a default image in case the src attribute of an html ...
Assuming that item has a property url that might be null, when it is then the image will show up as broken. That...
Read more >
Fallback image if src doesn't exist for image tag – ReactJS
If the image can't be found it the callback is invoked. In the callback I set the src of the image tag to...
Read more >
<img>: The Image Embed element - HTML - MDN Web Docs
The above example shows usage of the <img> element: The src attribute is required, and contains the path to the image you want...
Read more >
How to Set the Equivalent of “src” Attribute of an <img> Tag in ...
In this snippet, you can find the solution of setting the equivalent of “src” attribute of an tag. For that, use the content...
Read more >
How To Use In HTML »
There are three different kinds of URLs that can be used in the src attribute: ... and it's also reasonable to hotlink an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found