Closed seanw closed 3 years ago
Contentful style-background-images...LCP uses simple heuristics to exclude background images with a background role...The heuristics to identify a background-purposed image may include: ... Document position - background images of the document's or its are more likely to serve as a background for the page.
- Will this definition be made more exact to make it clear that background images on the
<body>
or<html>
will always be ignored as the LCP?
It does say that right below that paragraph, and yes we do ignore those at the moment.
- Will a viewport sized background image on a
<header>
at the top of the page be flagged as the LCP?
I believe so but you could check with a sample website where you do that. Presumably most sites don't use a giant header? Not sure why you're asking this.
It would be frustrating to change the web design and code of a site to improve the LCP time based on the above and then for the definition of LCP to change.
One thing we've though about is whether we should just exclude any large (or viewport sized) background images from being LCP, though as of now we don't have plans to change this.
Additionally, this seems to have a big impact on web design in general if you cannot rely on the above, especially if LCP timings start to influence your search rank. Many sites use large background header images that are only decorative that don't stop the (contentful) header text from being quickly readable - if large background images always tank your LCP score, wouldn't your only options be to use e.g. images that are smaller than the header text or only SVG backgrounds/images?
While some background images are decorative, others are actually important content of the website, and it can be hard for an algorithm to distinguish this. We intend to document any changes in the LCP documentation here https://chromium.googlesource.com/chromium/src/+/master/docs/speed/metrics_changelog/lcp.md.
Thanks for your reply.
While some background images are decorative, others are actually important content of the website, and it can be hard for an algorithm to distinguish this.
To explain myself better, what I'm really asking is: What are the guidelines on how to design web pages that feature large decorative only (i.e. non-contentful) images in the header that will get a performant LCP score?
The recommended approach is to use background: url
on the <html>
element and there isn't an alternative? I've personally not seen this approach before, but if it's the only way to get a good LCP score with a large background image, I can see the current heuristic pushing developers in that direction.
Usually you'd style the <header>
element but from some testing myself this will get flagged as the LCP. Is this just a case of a false positive or there's a reason the <header>
approach should be scored lower than the <html>
approach?
To explain myself better, what I'm really asking is: What are the guidelines on how to design web pages that feature large decorative only (i.e. non-contentful) images in the header that will get a performant LCP score?
@philipwalton could probably respond this better, but note that if the intrinsic size of the image is small then it will likely not be considered LCP. And if its intrinsic size is large then it hopefully isn't a heavyweight resource anyways, since it's just decorative? I.e. having a heavyweight decorative image is probably not the best for performance as it may slow down the other content.
- The recommended approach is to use
background: url
on the<html>
element and there isn't an alternative? I've personally not seen this approach before, but if it's the only way to get a good LCP score with a large background image, I can see the current heuristic pushing developers in that direction.
We did see cases like this, which is what triggered the exclusion. It's certainly not a perfect heuristic.
- Usually you'd style the
<header>
element but from some testing myself this will get flagged as the LCP. Is this just a case of a false positive or there's a reason the<header>
approach should be scored lower than the<html>
approach?
Setting a background for a <header>
(or do you mean <head>
? Same reasoning applies though) )would result in something totally different from setting it in the <html>
or <body>
, so I'm not sure why you mention these as interchangeable... Note the heuristic we have is to cover cases where the image is really just decorative, but covering the majority of the site (which is not really the case for a background of the header).
@npm1
having a heavyweight decorative image is probably not the best for performance as it may slow down the other content.
Here's a minimal example of using background: url
to implement the same page design getting very different LCP scores:
body
element and gets a 0.8s LCP score:https://clever-hawking-7f390b.netlify.app/lcp-body-background/
header
element and gets a (red) 3.4s LCP score:https://clever-hawking-7f390b.netlify.app/lcp-header-background/
What I'm getting at is:
Page designs with big decorative images like this are common and popular.
When Google start incorporating LCP into search rankings, developers are going to look for ways to get the best LCP score.
The body
background url approach I used above seems like a hack to me (with likely cleaner variations) but that's what the current heuristics are going to encourage.
My suggestions are:
If the body
background url example above should really be getting a bad LCP score, I would improve the heuristic to correct for this as it's likely to get abused eventually.
If it's possible to implement a page design like the above while getting a good LCP score, I would add some guidelines on the recommended way to go about this seeing as it's such a common page design. I'd be happy to contribute some text for this if that would help.
Hope that makes sense. The context here is that when I'm consulting for a client to improve their website performance, I want to know if it's best to entirely avoid page designs like in the example I gave (unless the background has a low file size).
Thanks, the examples are super helpful :) I think I would be in favor of excluding any background image which occupies all of the viewport, and not just those which are set in the body
or html
.
I think I would be in favor of excluding any background image which occupies all of the viewport, and not just those which are set in the body or html.
If you did this, how are you going to stop blackhat SEO developers from gaming the LCP metric (for potential search ranking benefits in the future) by moving their web page header content into background images?
In terms of resolving this issue ticket, are we in agreement then that the current document needs to be improved to make it clear on how to get a good LCP score for web designs that use large decorative images? See https://wordpress.com/themes and https://themes.shopify.com/ for some evidence that web designs like this are very common, so that it's essential that developers know without ambiguity which techniques can be relied upon (and which techniques are blackhat and may be closed off in the future).
Sean, we’re not in a position to make any statements about how the Google Search team will deal with malicious actors — that’s for them to figure out. All metrics are gameable and it’s not a new problem for them.
What we do need to think about is what behaviors we want to encourage to be the norm and how to make them easy. Which is to say, we should have a well documented best practice for how to deliver LCP-well-performing designs with large decorative images. That said, I'm not convinced that this needs to live in the spec, or that it’s the right place for it: this is not where an average developer will look for guidance. CC @philipwalton for input.
I'll close this issue. Any additional guidance should probably live in sites like MDN or web.dev.
I use SVG image as div background and it's done
While some background images are decorative, others are actually important content of the website, and it can be hard for an algorithm to distinguish this. We intend to document any changes in the LCP documentation here https://chromium.googlesource.com/chromium/src/+/master/docs/speed/metrics_changelog/lcp.md.
Detecting decorative images shouldn't be difficult. There are well defined patterns that already exist.
<img alt="">
<img role="presentation">
aria-hidden
: <img aria-hidden="true">
It seems to me at least that decorative images should be excluded from being LCP element candidates if for no other reason that they are only actual relevant to a subset of visitors that do not suffer from disabilities.
My 2¢ :smiley:
Will this definition be made more exact to make it clear that background images on the
<body>
or<html>
will always be ignored as the LCP?Will a viewport sized background image on a
<header>
at the top of the page be flagged as the LCP?It would be frustrating to change the web design and code of a site to improve the LCP time based on the above and then for the definition of LCP to change.
Additionally, this seems to have a big impact on web design in general if you cannot rely on the above, especially if LCP timings start to influence your search rank. Many sites use large background header images that are only decorative that don't stop the (contentful) header text from being quickly readable - if large background images always tank your LCP score, wouldn't your only options be to use e.g. images that are smaller than the header text or only SVG backgrounds/images?