How to reduce AdSense layout shift on an Astro blog
Measure ad-related layout shift in Astro, reserve space before an in-article slot loads, and distinguish a mobile lab result from real visitor data.
- Author
- Salon Rai
- 4 min read
If a paragraph slides down just as someone starts reading it, inspect the ad slot above it. An Astro page can deliver the entire article as static HTML and still move when an AdSense placement fills. Reserve space in that first HTML response, then measure whether the text moves when the slot changes height.
Identify the element that changed size
Record a page load in Chrome DevTools’ Performance panel. Use a mobile viewport, start the recording before navigation, and inspect the layout shift events. A highlighted paragraph may be the victim of the shift. Look immediately above it for the image, embed, label or ad container whose height changed between frames. Chrome DevTools Performance reference
Cumulative Layout Shift (CLS) measures unexpected movement in the viewport. It considers both the area affected and the distance moved. Page CLS uses the largest cluster of qualifying shifts in a session window. A measurement from loading a single page in a lab captures only the events that occurred during that recording. Google’s explanation of CLS
Reproduce the movement without requesting an ad
Save this as an HTML file and open it at a 390 by 844 pixel viewport. Reload once with no reservation and once with min-height: 250px on the slot. The delayed expansion stands in for a placement receiving content. The gray article gives the eye a stable edge to follow.
<!doctype html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* { box-sizing: border-box; }
body { margin: 0; }
header { height: 80px; }
#slot { min-height: 0; }
article { height: 450px; background: #ddd; }
</style>
<header>Story</header>
<aside id="slot"></aside>
<article>Text</article>
<script>
const slot = document.querySelector('#slot');
setTimeout(() => { slot.style.height = '250px'; }, 350);
</script>
In a local headless Chromium 159 run with this geometry, the unreserved article moved from 80 to 330 pixels below the top of the page. The browser reported one layout shift with a score of approximately 0.246. With 250 pixels reserved, the article began and ended at 330 pixels and the browser reported zero shift events during the observation. The run simulated a single fill with no user input. It measured neither live ads nor visitor CLS.
Reserve space when Astro renders the placement
On this blog the ad component renders its label and a wrapper around the ad unit. The in-article configuration specifies a 250-pixel minimum height. The following Astro excerpt shows the arrangement with a slot for the publisher’s own ad markup. Put the sizing on an element present at first paint. Adding the wrapper only after the ad script loads allows the original jump to happen.
<aside aria-label="Advertisement">
<p>Advertisement</p>
<div class="ad-space"><slot /></div>
</aside>
<style>
.ad-space {
min-height: 250px;
}
</style>
A minimum allows a taller creative to expand. If the actual fill is 280 pixels high and the reservation is 250 pixels, there are still 30 pixels of growth to account for. A fixed height with overflow clipping can hide part of a creative. Measure the sizes served at the widths your readers use before choosing a reservation. Google’s layout-shift optimization guide
Check empty slots and narrow screens
An empty placement presents a different decision. Keeping the reservation can leave a gap. Removing it after first paint can pull the next paragraph up, also producing movement. Test an empty slot and a delayed fill as separate cases. If you know at render time that a page has no eligible placement, omit the wrapper then.
A slot below the fold can fill before a reader reaches it. The same slot on a longer-lived page may fill while it is visible. Repeat the recording after scrolling to an article’s first in-content placement. Include the width at which your layout changes from one column to two and check that the advertisement label is already present before the unit loads.
Separate a sizing problem from a late insertion
Inspect the original HTML and the DOM after load. If the original HTML already has a 250-pixel reservation and the filled unit needs 300 pixels, the opening gap exists but is undersized. If the original HTML contains only the paragraph and a script later inserts a 250-pixel wrapper above it, the entire placement is late. Raising the minimum height on that late wrapper can increase the displacement. The fixes belong in different places.
A useful measurement is the top edge of the same paragraph before and after the fill, recorded at the same scroll position. Pair that distance with the viewport size and the browser’s reported shift. The distance explains what a reader experienced. The score describes how much of the viewport participated in the movement. A shift occurring entirely outside the viewport can leave the current view stable.
For a manually placed unit, keep the reservation specific to that placement. The blog’s in-article slot and sidebar slot occupy different columns at different widths. A single global minimum can waste space on small screens and still underestimate a taller sidebar placement. Automatically inserted placements require their own diagnosis because the publisher’s article wrapper may sit elsewhere on the page.
Next steps
Keep the before and after traces with the viewport dimensions and slot heights. Use the lab result to confirm the cause and the deployed site’s field data to see what visitors experience over time. Revisit the reservation if the layout, ad formats or distribution of screen widths changes. Google’s guide to lab and field data

Written by