ApoorvSaxena / ApoorvSaxena/lozad.js

Attribute-updating order in load() results in Safari loading images twice

Open
#99 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.5k
Forks
435
PR merge metrics
No merged PRs in 30d

Description

The default function to load images first copies `data-src` to `src`, followed by `data-srcset` to `srcset`.
This means the image tag gets updated twice: first with a src-attribute and then with a srcset-attribute.
The result is Safari loading the image defined in the src-attribute and then *also* loading the best-suited image from the srcset, since for a short moment it is a default image tag before it becomes an image tag with a srcset.

I have tested this with Chrome and Safari; Safari was the only one to do this, but other browsers could be affected as well.

Solution: Change the order in which the attributes are updated, so that `srcset` is defined before `src`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.