Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lazy Loading to images and iframes #331

Closed
wants to merge 0 commits into from

Conversation

RiccardoMasutti
Copy link
Contributor

@RiccardoMasutti RiccardoMasutti commented Jan 15, 2020

(Replaced by #340)

Why native lazy-loading?

According to HTTPArchive, images are the most requested asset type for most websites and usually take up more bandwidth than any other resource. At the 90th percentile, sites send about 4.7 MB of images on desktop and mobile. That's a lot of cat pictures.

Embedded iframes also use a lot of data and can harm page performance. Only loading non-critical, below-the-fold images and iframes when the user is likely to see them improves page load times, minimizes user bandwidth, and reduces memory usage.

SEO Benefits

Google has indicated site speed (and as a result, page speed) is one of the signals used by its algorithm to rank pages. And research has shown that Google might be specifically measuring time to first byte as when it considers page speed. In addition, a slow page speed means that search engines can crawl fewer pages using their allocated crawl budget, and this could negatively affect your indexation.

Page speed is also important to user experience. Pages with a longer load time tend to have higher bounce rates and lower average time on page. Longer load times have also been shown to negatively affect conversions.

Currently, there are two ways to defer the loading of off-screen images and iframes:

  • Using the Intersection Observer API
  • Using scroll, resize, or orientationchange event handlers

Either option can let developers include lazy-loading functionality, and many developers have built third-party libraries to provide abstractions that are even easier to use. With lazy-loading supported directly by the browser, however, there's no need for an external library. Native lazy loading also ensures that deferred loading of images and iframes still works even if JavaScript is disabled on the client.

Starting with Chrome 76, we are able to use the new loading attribute to lazy-load resources without the need to write custom lazy-loading code or use a separate JavaScript library.

Demo:
ezgif-7-61e4604beabd

Source: https://web.dev/native-lazy-loading/

@RiccardoMasutti RiccardoMasutti requested a review from m52go January 16, 2020 17:33
Copy link
Contributor

@m52go m52go left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't see a difference in the way images are loaded, and browser support isn't great, but I don't see a downside either.

Please double-check that spacing is good throughout...I spotted 1 error.

_includes/footer.html Outdated Show resolved Hide resolved
@RiccardoMasutti
Copy link
Contributor Author

RiccardoMasutti commented Jan 27, 2020

To be honest, I don't see a difference in the way images are loaded, and browser support isn't great, but I don't see a downside either.

Please double-check that spacing is good throughout...I spotted 1 error.

We delay the loading of images until the point where user really need it. This makes the website load faster, the user saves bandwidth and the overall SEO is improved.
Putting in simple words, on demand object loading rather than loading objects unnecessarily.

@m52go
Copy link
Contributor

m52go commented Jan 27, 2020

Yeah I think I was testing on Firefox, which isn't supported yet. Works on Chromium though.

https://caniuse.com/#feat=loading-lazy-attr

@m52go
Copy link
Contributor

m52go commented Jan 28, 2020

@RiccardoMasutti this is ready...merge conflicts just need to be fixed.

@FKrauss
Copy link
Contributor

FKrauss commented Feb 7, 2020

https://caniuse.com/#feat=loading-lazy-attr

This does leave out over a third of our website users:
image

But when it is not supported, what happens? does the page load all the content? If that is the case then we still get the SEO benefit of having faster loading times?

@RiccardoMasutti
Copy link
Contributor Author

@FKrauss yes, unsupported browsers load images as usual.

It will boost SEO because of Google renders pages with latest Chromium updates

@RiccardoMasutti
Copy link
Contributor Author

RiccardoMasutti commented Feb 7, 2020

The loading attribute can be treated as a progressive enhancement. Browsers that support it can lazy-load images and iframes. Those that don't yet can load images just like they would today.

In terms of cross-browser support, loading should be supported in Chrome 76 and any Chromium 76-based browsers. There is also an open implementation bug for Firefox.

A similar API was proposed and used in IE and Edge but was focused on lowering the download priorities of resources instead of deferring them entirely. It was discontinued in favour of resource hints.

Btw now Edge ships as Chromium-based so it will add loading feature ;)

@FKrauss
Copy link
Contributor

FKrauss commented Feb 7, 2020 via email

@RiccardoMasutti
Copy link
Contributor Author

Cool, so that's a non issue in terms of user impact

Exactly. Let's say it is a long term investment as loading="lazy" is the future and will become a standard

@RiccardoMasutti
Copy link
Contributor Author

RiccardoMasutti commented Feb 7, 2020

It will make the site faster, more appreciated (by users and Google). 47% of content type are images and 83% of requests are from images.

https://tools.pingdom.com/#5c08661c34000000

Content size by content type:

CONTENT TYPE PERCENT SIZE
Image 46.69% 222.2 KB

Requests by content type:

CONTENT TYPE PERCENT REQUESTS
Image 83.05% 49

@RiccardoMasutti
Copy link
Contributor Author

@FKrauss @m52go should be ready to merge

@m52go
Copy link
Contributor

m52go commented Feb 10, 2020

Huh? This PR closed just as I pushed an update 🤔

@RiccardoMasutti can you reopen it? I don't have a button to reopen.

@m52go
Copy link
Contributor

m52go commented Feb 10, 2020

Ah shoot, I screwed it up...force-pushed an empty set of changes (or something) and that automatically closed the PR.

Correction is here. @RiccardoMasutti would you like to make a new PR from that branch? That's ready to merge.


FWIW there were over 50 merge conflicts that had to be corrected one by one.

Screenshot from 2020-02-10 00-46-25-2

I really need you to take care of this type of stuff in the future...I'm happy to explain it to you, but I can't spend time doing it myself. It's a contributor's job to make their PRs ready to merge—as maintainer, if I can't merge PRs with little/no work, I'm going to have to close them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants