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 for Homepage Images and Check script #5998

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

shivamgupta2020
Copy link
Contributor

Fixes #5981

Proposed Changes

  • added lazy load in homepage images

Copy link

knative-prow bot commented May 28, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: shivamgupta2020
Once this PR has been reviewed and has the lgtm label, please assign dsimansk for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot requested review from nainaz and skonto May 28, 2024 23:49
@knative-prow knative-prow bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 28, 2024
Copy link

netlify bot commented May 28, 2024

Deploy Preview for knative ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 34b7d52
🔍 Latest deploy log https://app.netlify.com/sites/knative/deploys/6668bf5c7f3a05000946eb2f
😎 Deploy Preview https://deploy-preview-5998--knative.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@aliok
Copy link
Member

aliok commented May 29, 2024

@shivamgupta2020

The check script should do these:

  • Build the website
  • Parse HTML pages that are built
  • Check for img tags without lazy
  • Report the locations (file, line number) of the tags w/o lazy attribute in the script logs (stdout)
  • Fail (by exiting with a code that's not zero)

This script should be running in a Github action.

I would recommend this approach:

  1. Write that script (can be a Python script)
  2. Include it in the PR, with documentation and dependencies (requirements.txt that can be used by pip)
  3. Get feedback, make sure it works
  4. Then create a GitHub action that runs the script

@shivamgupta2020
Copy link
Contributor Author

Thanks, @aliok , for the suggestions. I’m currently working on the script part and will include all your suggestions in a new commit as soon as possible.

@shivamgupta2020
Copy link
Contributor Author

shivamgupta2020 commented May 31, 2024

@shivamgupta2020

The check script should do these:

  • Build the website
  • Parse HTML pages that are built
  • Check for img tags without lazy
  • Report the locations (file, line number) of the tags w/o lazy attribute in the script logs (stdout)
  • Fail (by exiting with a code that's not zero)

This script should be running in a Github action.

I would recommend this approach:

  1. Write that script (can be a Python script)
  2. Include it in the PR, with documentation and dependencies (requirements.txt that can be used by pip)
  3. Get feedback, make sure it works
  4. Then create a GitHub action that runs the script

Should the script also run for v1.13, v1.12, and the development folder present in the "site" folder?

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 1, 2024
@knative-prow knative-prow bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 4, 2024
import os
import sys
import subprocess
from bs4 import BeautifulSoup
Copy link
Member

Choose a reason for hiding this comment

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

Is it a possibility to use standard Python libraries for parsing HTML files?

What's your opinion here @shivamgupta2020 ? We need to instruct people to install some dependencies if we go with BeautifulSoup. However, we might have some non-standard HTML content that might not be parseable with standard Python libraries.

Let's ask @knative/productivity-leads and @cardil specifically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aliok, I experimented with HTMLParser and IXML for parsing HTML files, but encountered numerous errors and incomplete parsing. Therefore, I switched to BeautifulSoup. I also think we should gather opinions from others on this approach.

Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines 6 to 12
def build_website():
"""Build the website using the specified command."""
try:
subprocess.check_call(['./hack/docker/test.sh'])
except subprocess.CalledProcessError as e:
print(f"Website build failed: {e}")
sys.exit(1)
Copy link
Member

Choose a reason for hiding this comment

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

Please leave this part out of the script.

This script will eventually run in a GitHub Actions workflow:

  • Build the website
  • Run the script
    • If there are images w/o loading=lazy, script should fail
    • If there are no images, script should exit successfully

Can you put the script in a GitHub actions workflow please?

Also, we need to document this change with instructions. In the relevant section here: https://github.com/knative/docs/blob/main/contribute-to-docs/README.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sure, I will remove the build function from the script.
I will look into the GitHub action workflow and add the script as soon as possible.

build_website()


base_dir = 'site'
Copy link
Member

Choose a reason for hiding this comment

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

Please make this configurable. Script should receive the directories to check HTML files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The function runs on the "site" folder because this folder is created after the build command. That's why I set base_dir = 'site.'
Why do we need to make it configurable?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Let's leave as is. I need to check this later.

@knative-prow knative-prow bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 11, 2024
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 11, 2024
@shivamgupta2020
Copy link
Contributor Author

I've created the workflow file as @aliok suggested. Currently, most of the images on the website are not lazy-loaded, resulting in many errors. Could you please check the script output on your local machine to verify it's working as expected? Also, please review the workflow code to ensure it's implemented correctly.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Site Performance with Lazy Loading and WEBP Images
3 participants