Skip to content

Commit

Permalink
Add LCP Discovery Delay
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfranklin committed Feb 18, 2025
1 parent ecb4bd0 commit c696eb8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<li><a href="initiators/index.html">initiators</a></li>
<li><a href="layout-shift/index.html">layout-shift</a></li>
<li><a href="lcp-critical-path/index.html">lcp-critical-path</a></li>
<li><a href="lcp-discovery-delay/index.html">lcp-discovery-delay</a></li>
<li><a href="lcp-iframes/index.html">lcp-iframes</a></li>
<li><a href="lcp-image-high-fetchpriority/index.html">lcp-image-high-fetchpriority</a></li>
<li><a href="lcp-large-image/index.html">lcp-large-image</a></li>
Expand Down
3 changes: 3 additions & 0 deletions lcp-discovery-delay/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const image = document.createElement('img');
image.src = 'lcp-image.jpg';
document.body.appendChild(image);
16 changes: 16 additions & 0 deletions lcp-discovery-delay/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html>
<head>
<title>LCP Discovery Delay</title>
<script src="./render-blocking-script.js"></script>
</head>
<body>
<p>In this example the LCP image is discovered late because:</p>
<ul>
<li>
The page has a render blocking script with a sync <code>sleep()</code> call for 1 second.
</li>
<li>The <code>app.js</code> script is the one that injects the LCP image..</li>
</ul>
<script src="./app.js"></script>
</body>
</html>
Binary file added lcp-discovery-delay/lcp-image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions lcp-discovery-delay/render-blocking-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function sleepFor(sleepDuration) {
let now = new Date().getTime();
while (new Date().getTime() < now + sleepDuration) {}
}
sleepFor(1_000);

0 comments on commit c696eb8

Please sign in to comment.