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

RFC: Optimize pre-rendered pages for LCP #122

Open
BioPhoton opened this issue Jul 11, 2022 · 1 comment
Open

RFC: Optimize pre-rendered pages for LCP #122

BioPhoton opened this issue Jul 11, 2022 · 1 comment
Labels
bootstrap performance Bootstrap performance improvement LCP

Comments

@BioPhoton
Copy link
Member

BioPhoton commented Jul 11, 2022

Motivation

Dynamic pages are hard to optimize for the LCP as we can't determine the LCP before executing the page.
It is important to optimize the LCP because it is part of the core web vitals and has a direct impact on user experience.
If we could know the LCP we could use preload and fetch priority to increase the network priority and load the LCP image much faster.

This can be applied to pre-rendered pages.

e.g. inject

  • <img src="img.png" fetchpriority="high" />
  • <link rel="preload" as="image" href="img.png" fetchpriority="high" />

State of the art

ATM preloading of images is done manually.
An example is manually adding the LCP image in the index.html. This can only improve situations where the LCP is static.

Idea

For pre-rendered pages we can run analyzing tools against the page e.g. lighthouse and determine the LCP and if it is an image.
Here is a detailed definition LCP.

In our case the following content is relevant:

  • <img> elements
  • <image> elements inside an <svg> element
  • <video> elements (the poster image is used)
  • An element with a background image loaded via the url()

After identifying the LCP element and its content source we can insert a link tag using the preload rel attribute to improve the download prioritization of the content by the browser, thus overwriting the HTML file of the pre-rendered page.

Implementation proposal

As the code should also be executed in the CI pipeline we should create a CLI executable in the CI.
The CLI should maintain the following commands:

  • Optimize (It measures the LCP, and then injects the LCP as a preload link tag and re-analyzes the LCP).
  • Analyze (Determent if LCP is the image or video, determine if the rendered size and the intrinsic size are the same or smaller and if it's delivered in a next-gen format).
@push-based-bot
Copy link

The PoC is working now! 🎉🎉🎉

@BioPhoton BioPhoton added bootstrap performance Bootstrap performance improvement LCP labels Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bootstrap performance Bootstrap performance improvement LCP
Projects
None yet
Development

No branches or pull requests

2 participants