docs icon indicating copy to clipboard operation
docs copied to clipboard

Improve Site Performance with Lazy Loading and WEBP Images

Open shivamgupta2020 opened this issue 1 year ago • 14 comments
trafficstars

Describe the change you'd like to see Implement two changes to enhance site performance:

  1. Add loading="lazy" to image tags to improve Cumulative Layout Shift (CLS).
  2. Convert PNG/JPG/JPEG images to WEBP format for faster loading times.

Additional context These optimizations will reduce initial page load time and bandwidth usage, improving user experience and SEO.

shivamgupta2020 avatar May 20 '24 19:05 shivamgupta2020

Hey @shivamgupta2020

Thanks a lot for the suggestions.

I will have some comments...

Add loading="lazy" to image tags to improve Cumulative Layout Shift (CLS).

Sounds good.

Convert PNG/JPG/JPEG images to WEBP format for faster loading times.

We will need a bash script that iterates over the website content and converts images to webp. We can't do this manuallly. This also means, we need another script that checks if images are converted to webp as a GitHub+Prow check and blocks merging the PR if there are images not converted.

However, let's talk about specifics later. We would need some data first, to see how much improvement there is.

We would need 4 data:

  • What's the page size and page load time currently?
  • Same metrics, but with loading=lazy
  • Same metrics, but with webp
  • Same metrics, but with both loading=lazy and webp

I don't expect to see these numbers for the entire website. Only the homepage is enough.

aliok avatar May 22 '24 06:05 aliok

@aliok Here are the metrics for all four of you requested.

Metrics without loading=lazy and webp:- metrics without lazyloading   webp Metrics wtth webp:- metrics with webp Metrics with loading=lazy:- metrics with lazy loading Metrics with loading=lazy and webp:- metrics with lazy loading and webp

shivamgupta2020 avatar May 22 '24 10:05 shivamgupta2020

@shivamgupta2020 what's the tool you've used to collect these numbers? I am curious.

aliok avatar May 22 '24 13:05 aliok

@shivamgupta2020 what's the tool you've used to collect these numbers? I am curious.

I used Google Lighthouse.

shivamgupta2020 avatar May 22 '24 13:05 shivamgupta2020

/assign

shivansh-bhatnagar18 avatar May 22 '24 19:05 shivansh-bhatnagar18

Hi @shivansh-bhatnagar18 , I've completed most of the work on this issue and am waiting for the maintainer's approval to raise a PR. You can contribute to other issues, so I'm unassigning you for now. /unassign @shivansh-bhatnagar18

shivamgupta2020 avatar May 22 '24 23:05 shivamgupta2020

@shivamgupta2020 I see there's not much improvement with webp. Let's not go that route.

Can you create a small POC for using loading=lazy? I wonder how we can do that with Markdown and MkDocs

aliok avatar May 23 '24 06:05 aliok

/assign shivamgupta2020

aliok avatar May 23 '24 06:05 aliok

@aliok So, I looked into it online. You can make images load lazily by adding {: loading=lazy } to the image tag. Reference:-

  1. https://github.com/squidfunk/mkdocs-material/issues/1867
  2. https://squidfunk.github.io/mkdocs-material/reference/images/#image-alignment

shivamgupta2020 avatar May 23 '24 10:05 shivamgupta2020

Thanks @shivamgupta2020

I think I would go this route...

I would create a PR with 2 things:

  • Homepage images converted to lazy
  • A script (in Python) that checks that page for any images without lazy loading and fails --> add a new GitHub action for this

aliok avatar May 27 '24 06:05 aliok

Hello @aliok, @shivamgupta2020!

I followed the discussion, and this enhancement looks really interesting to me. If there's any way I can help, especially with the Python scripting part, I'm more than willing to do so.

One aspect we need to consider is its impact on users with slower internet speeds, as it could cause layout shifting issues. For example, when I tested lazy loading on the first two images with a slow internet connection, there were noticeable layout shifts. While it's not a major issue, it's worth thinking about possible ways to mitigate it. What are your thoughts on this?

Screenshot (61)

rohitsrma avatar May 27 '24 09:05 rohitsrma

Hello @aliok, @shivamgupta2020!

I followed the discussion, and this enhancement looks really interesting to me. If there's any way I can help, especially with the Python scripting part, I'm more than willing to do so.

One aspect we need to consider is its impact on users with slower internet speeds, as it could cause layout shifting issues. For example, when I tested lazy loading on the first two images with a slow internet connection, there were noticeable layout shifts. While it's not a major issue, it's worth thinking about possible ways to mitigate it. What are your thoughts on this?

Screenshot (61)

Hi Rohit, I want to try the scripting part first. If I encounter any issues, I'll look for your help. Regarding CLS on slower internet speeds, I suggested using WebP format, but as @aliok mentioned, it's making little difference. Can you recommend any alternative ways to improve CLS?

shivamgupta2020 avatar May 27 '24 11:05 shivamgupta2020

@shivamgupta2020 I'll do some research regarding alternative ways to improve CLS and update you.

rohitsrma avatar May 28 '24 09:05 rohitsrma

This issue is stale because it has been open for 90 days with no activity. It will automatically close after 30 more days of inactivity. Reopen the issue with /reopen. Mark the issue as fresh by adding the comment /remove-lifecycle stale.

github-actions[bot] avatar Aug 27 '24 01:08 github-actions[bot]