Skip to content

Commit f8b333c

Browse files
Attempt to improve LCP
1 parent 457f910 commit f8b333c

File tree

3 files changed

+83
-6
lines changed

3 files changed

+83
-6
lines changed

src/components/Dots.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="absolute top-0 left-0 flex h-12 w-full justify-center p-2">
2-
<div class="bg-dots-light dark:bg-dots-dark h-12 w-full bg-repeat-x"></div>
2+
<div class="bg-dots-light dark:bg-dots-dark h-12 w-full bg-repeat-x" style="content-visibility: auto;"></div>
33
</div>

src/components/ShowArtwork.astro

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,20 @@ const { image } = Astro.props;
3333
</a>
3434

3535
<script>
36-
import Atropos from 'atropos';
36+
// Defer Atropos initialization to after LCP
37+
function initAtropos() {
38+
import('atropos').then((module) => {
39+
const Atropos = module.default;
40+
Atropos({
41+
el: '.show-art'
42+
});
43+
});
44+
}
3745

38-
Atropos({
39-
el: '.show-art'
40-
});
46+
// Initialize after page load to avoid blocking LCP
47+
if (document.readyState === 'complete') {
48+
initAtropos();
49+
} else {
50+
window.addEventListener('load', initAtropos);
51+
}
4152
</script>

src/layouts/Layout.astro

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,35 @@ const { imageUrl, title } = Astro.props;
3535
const canonicalURL =
3636
Astro.props.canonicalURL ?? new URL(Astro.url.pathname, Astro.site);
3737
const description = Astro.props.description ?? starpodConfig.description;
38+
39+
function extractDomain(url: string): string | null {
40+
try {
41+
return new URL(url).hostname;
42+
} catch {
43+
return null;
44+
}
45+
}
46+
47+
function getExternalDomains(): string[] {
48+
const domains = new Set<string>();
49+
const siteHostname = Astro.site?.hostname;
50+
51+
// Add RSS feed domain
52+
const feedDomain = extractDomain(starpodConfig.rssFeed);
53+
if (feedDomain && feedDomain !== siteHostname) {
54+
domains.add(feedDomain);
55+
}
56+
57+
// Add image domain if it's external
58+
const imageDomain = extractDomain(show.image);
59+
if (imageDomain && imageDomain !== siteHostname) {
60+
domains.add(imageDomain);
61+
}
62+
63+
return Array.from(domains);
64+
}
65+
66+
const externalDomains = getExternalDomains();
3867
---
3968

4069
<!doctype html>
@@ -92,10 +121,45 @@ const description = Astro.props.description ?? starpodConfig.description;
92121

93122
<meta property="og:site_name" content={show.title} />
94123

95-
<link rel="preload" as="image" href={show.image} />
124+
<!-- Preload critical resources for faster LCP -->
125+
<link rel="preload" as="image" href={show.image} fetchpriority="high" />
96126

97127
<Font cssVariable="--astro-font-inter" preload />
98128

129+
<!-- DNS prefetch for external resources -->
130+
{
131+
externalDomains.map((domain) => (
132+
<>
133+
<link rel="dns-prefetch" href={`//${domain}`} />
134+
<link rel="preconnect" href={`https://${domain}`} crossorigin />
135+
</>
136+
))
137+
}
138+
139+
<!-- Prefetch for Vercel image optimization -->
140+
{Astro.site && <link rel="preconnect" href={Astro.site.origin} />}
141+
142+
<!-- Critical CSS for LCP optimization -->
143+
<style>
144+
/* Critical styles for above-the-fold content */
145+
body {
146+
font-family: 'Inter', system-ui, sans-serif;
147+
margin: 0;
148+
}
149+
150+
.atropos-inner img {
151+
max-width: 100%;
152+
height: auto;
153+
display: block;
154+
}
155+
156+
/* Ensure LCP image renders quickly */
157+
.show-art img {
158+
content-visibility: auto;
159+
contain: layout style paint;
160+
}
161+
</style>
162+
99163
<Schema
100164
slot="head"
101165
item={{
@@ -133,6 +197,7 @@ const description = Astro.props.description ?? starpodConfig.description;
133197
<div class="relative z-10 mx-auto lg:min-h-full lg:flex-auto">
134198
<div
135199
class="bg-light-card dark:bg-dark-card m-2 rounded-lg pt-10 pb-4 lg:pt-16 lg:pb-12"
200+
style="contain: layout style;"
136201
>
137202
<ShowArtwork image={show.image} />
138203

@@ -167,6 +232,7 @@ const description = Astro.props.description ?? starpodConfig.description;
167232
<div class="relative mt-2 pt-16">
168233
<div
169234
class="bg-gradient-light dark:bg-gradient-dark absolute top-0 right-0 left-0 z-0 h-80 w-full opacity-30"
235+
style="content-visibility: auto;"
170236
>
171237
</div>
172238

0 commit comments

Comments
 (0)