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

Why I get LCP less than FCP? #369

Closed
xiaofud opened this issue Jul 14, 2023 · 4 comments
Closed

Why I get LCP less than FCP? #369

xiaofud opened this issue Jul 14, 2023 · 4 comments

Comments

@xiaofud
Copy link

xiaofud commented Jul 14, 2023

Javascript code

<script type="module">
        import {onCLS, onFID, onLCP, onFCP} from 'https://unpkg.com/web-vitals@3?module';

        onCLS(console.log);
        onFCP(console.log);
        onLCP(console.log);
    </script>

console log
LCP less than FCP

The LCP element is an image and it's preloaded.
image

My Chrome version: Version 114.0.5735.198 (Official Build) (x86_64)

@tunetheweb
Copy link
Member

In theory this shouldn't be possible on a single page load. Do you have a URL where this can be reproduced?

@xiaofud
Copy link
Author

xiaofud commented Jul 15, 2023

In theory this shouldn't be possible on a single page load. Do you have a URL where this can be reproduced?

Hello, I can reproduce the issue at https://www.iq.com/, using following code snippet in console

const observer = new PerformanceObserver((entryList) => {

  for (const entry of entryList.getEntriesByName('first-contentful-paint')) {
    console.log('FCP candidate:', entry.startTime, entry);
  }

  for (const entry of entryList.getEntriesByType("largest-contentful-paint")) {
    console.log('LCP candidate:', entry.startTime, entry);
  }

  for (const entry of entryList.getEntriesByType("first-input")) {
    const delay = entry.processingStart - entry.startTime;
    console.log('FID candidate:', delay, entry);
  }

});

observer.observe({type: 'paint', buffered: true});
observer.observe({type: 'largest-contentful-paint', buffered: true});
observer.observe({type: 'first-input', buffered: true});
image

@philipwalton
Copy link
Member

philipwalton commented Jul 15, 2023

This is happening here because the LCP image is loaded cross-origin, so it's full timing information is not available and the API can only expose the loadTime value rather than the renderTime value.

If you want to enable full timing data for cross-origin images, you can add the Timing-Allow-Origin to those image responses (assuming you control the config for that server).

See this related issue for more details: #260 (comment)

@xiaofud
Copy link
Author

xiaofud commented Jul 17, 2023

This is happening here because the LCP image is loaded cross-origin, so it's full timing information is not available and the API can only expose the loadTime value rather than the renderTime value.

If you want to enable full timing data for cross-origin images, you can add the Timing-Allow-Origin to those image responses (assuming you control the config for that server).

See this related issue for more details: #260 (comment)

Thanks @philipwalton ! After adding Timing-Allow-Origin header using chrome plugin, I get the correct value.

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

No branches or pull requests

3 participants