What Moved My Lighthouse Scores: 5 Fixes on an Astro Site
Short answer: on a static Astro site the framework gets you most of the way, and the last points come from small, specific decisions: which CSS blocks rendering, what JavaScript runs while the page is still loading, whic
Short answer: on a static Astro site the framework gets you most of the way, and the last points come from small, specific decisions: which CSS blocks rendering, what JavaScript runs while the page is still loading, which font weight the text actually uses, and whether any image is being stretched. Here are the five changes that measurably moved the numbers on this site, with the measurements.
This site is built with Astro (static output) and Tailwind CSS v4, served from Cloudflare. It is a bilingual portfolio with a blog, a lot of animation on the home page, and almost no JavaScript elsewhere.
How I measured
Every number below is from Lighthouse in mobile mode, against a production build (astro build, served by the same server as the live site), never the dev server. Lab results vary from run to run, sometimes by 5 points and 150 ms of Total Blocking Time on the same page, so I ran each test several times and compare the runs, not a single score.
Lab scores are a debugging tool. What Google uses for ranking is field data from real visitors (Core Web Vitals over the last 28 days), so the goal is not a perfect 100 but no regressions you can measure.
1. Inline the CSS
The whole site compiles to about 9 KB of CSS after compression. As a separate file it was the only render-blocking request on every page: the browser had to fetch it before it could paint anything.
Astro can put the stylesheet straight into the HTML:
// astro.config.mjs
export default defineConfig({
build: { inlineStylesheets: "always" },
});
Result: LCP improved by 0.3β0.5 s on mobile.
This only pays off when the CSS is small. Inlined CSS is downloaded again with every page instead of being cached, so for a large stylesheet the separate, cached file is usually the better trade. Measure both.
2. Turn the loader off where people come to read
The site has an intro loader: βSoftware Developerβ decodes out of code glyphs while the statue resolves from an ASCII version of itself. It shows on a first visit and on a reload.
On the home page that is fine. On a blog post it was not. The loader rewrites its text on every frame, and on a page with a long article each of those updates made the browser recalculate the layout of the whole document. Total Blocking Time on a post was 450β480 ms.
Two changes fixed it:
-
No loader on posts. Readers arrive from search for the text, not for an intro. The layout takes a
preloader={false}prop, and the inline script that decides whether to show the loader skips it when the page opts out. - Use the font weight that is already preloaded. The body text of a post was set in weight 300, which is not one of the two weights the site preloads. It arrived late and the whole article was laid out a second time. Setting the text to the preloaded weight 400 removed that second layout, and it also reads better at length.
Result: TBT fell to 110β230 ms across runs, and the performance score went from 86 to 95β98.
3. Make the fallback font match the web font
Fonts are self-hosted WOFF2 files, subset to Latin and Latin Extended (the site has a Turkish version, so Δ, Ε, Δ± and Δ° have to stay). Only the two weights used above the fold are preloaded, and font-display: swap shows text immediately.
Swapping can still shift the layout when the web font arrives, because the fallback font has different metrics. A metric-matched fallback fixes that:
@font-face {
font-family: "Poppins Fallback";
src: local("Arial");
ascent-override: 93.62%;
descent-override: 31.21%;
line-gap-override: 8.92%;
size-adjust: 112.16%;
}
The page then uses font-family: "Poppins", "Poppins Fallback", sans-serif.
Result: Cumulative Layout Shift stays between 0.001 and 0.017 on the pages I measured, far below the 0.1 βgoodβ threshold.
4. Do not let the browser upscale an image
Best Practices was stuck at 96 on every page, with one warning: βServes images with low resolutionβ. The culprit was not a content image but a faint, decorative statue in the background of the menu. Its source was 448 px wide, and the menu displays it at up to 82% of the screen height, so the browser was stretching it.
The fix was a 2Γ version of that image (an upscale of the original; at the menuβs low opacity and in greyscale the softness does not show), with widths={[448, 672, 896]} so the browser picks the right size.
Result: Best Practices 96 β 100 on every page. When a warning appears on every page, look at the shared layout first: menus, headers and footers.
5. Watch what you ship that nobody sees
Two things on this site cost bytes without being visible:
- Share images. Each post gets a 1200Γ630 share image generated at build time with satori. I first exported them as PNG, which is lossless and very large for artwork. Switching to JPEG took them from about 1.1 MB to about 100 KB each. Lighthouse does not test them, but every link preview on LinkedIn or WhatsApp downloads one.
-
HTML comments. Astro keeps
<!-- -->comments from templates in the output. My code comments were adding about 2.3 KB to every page, and an AI-visibility checker I ran read them as the start of the page text. Writing them as{/* */}instead keeps them in the source only.
What the validator caught
Not Lighthouse, but worth running next to it: html-validate on the built pages found three things Lighthouse did not.
-
Inline styles from syntax highlighting. Astroβs default highlighter writes a
styleattribute on every token. The code samples on this blog are short, so I turned highlighting off (markdown.syntaxHighlight: false) and styled code blocks with the siteβs CSS. -
Heading ids with non-ASCII characters. Markdown heading ids kept Turkish letters, and the capital
Δ°became a lowercaseiplus a combining dot, which is not a valid id character. A small plugin now transliterates headings to ASCII slugs, and the table of contents uses the same function. -
A stale Markdown cache. After changing the Markdown settings, built pages still had the old heading ids: Astro caches rendered Markdown in
node_modules/.astro/data-store.json, and build caches can restorenode_modules. Aprebuildscript now deletes that file.
Frequently asked questions
Is a Lighthouse score of 100 worth chasing?Not as a goal on its own. Google ranks with field data from real visitors, and lab scores vary between runs. Fix what the report points to, check that LCP, CLS and INP are in the good range for real users, and stop when the changes no longer move the field data.
Should I always inline CSS in Astro?
Only when it is small. Inlining removes a render-blocking request but the CSS is downloaded with every page instead of being cached. For a few kilobytes that is a good trade; for a large stylesheet, measure before switching.
Why did removing a loader improve Total Blocking Time so much?
Because of what it touched, not how much JavaScript it was. It changed text on every frame while the page was still loading, and on a long page each change made the browser recalculate the layout of the whole document.
Conclusion
None of these changes is large. What they have in common is that I found each one by measuring the production build several times, looking at what the report actually blamed, and fixing that thing rather than following a generic checklist.
If you want a second pair of eyes on a slow site, get in touch.
Sources
- Astro: Configuration reference: build.inlineStylesheets
- web.dev: Largest Contentful Paint
- web.dev: Total Blocking Time
- web.dev: Improved font fallbacks
- Chrome for Developers: Lighthouse: serve images with appropriate resolution
- satori
- html-validate
Originally published on cengizhnx.dev.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.
