Are you sacrificing your Core Web Vitals to display Google AdSense ads? You don't have to choose between fast page load speeds and ad revenue. Lazy loading AdSense is the ultimate technical fix.
In my consulting experience, simply adding the default AdSense code block to a WordPress site can instantly drop mobile PageSpeed scores by 20 to 30 points. The adsbygoogle.js script initiates dozens of third-party network requests, skyrocketing your Total Blocking Time (TBT). In this technical guide, I'll show you exactly how to defer AdSense execution so your primary content loads first.
Table of Contents
The AdSense Performance Penalty Explained
When you paste standard AdSense code into your header, you are instructing the browser to fetch, parse, and execute heavy JavaScript payloads before it finishes rendering the actual text of your article. This creates severe bottlenecks:
- Main-thread blocking: AdSense scripts block the browser from executing other critical rendering tasks.
- Network congestion: The ads pull resources from multiple external domains, requiring costly DNS lookups and SSL handshakes.
- Layout Shifts: If ad units aren't given fixed dimensions, they will pop into place late, causing terrible Cumulative Layout Shift (CLS).
Step 1: Clean Up Your Existing Ad Code
The standard AdSense snippet includes a call to load the external script every single time an ad unit is placed. This is highly redundant.
<!-- REMOVE THIS LINE FROM EVERY AD UNIT -->
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- KEEP THIS PART -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
data-ad-slot="1234567890"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
By removing the <script src="..."> tag from all your individual ad units, you prevent the browser from attempting to load the core library prematurely.
Step 2: Choose Your Lazy Load Implementation
Now, we need to inject the adsbygoogle.js script exactly once, but only when it won't impact our Core Web Vitals.
Method A: On-Scroll Event (Recommended for Custom Sites)
This is the most effective method for hand-coded or custom PHP sites. The ad script will sit entirely dormant until the user scrolls, moves their mouse, or touches the screen.
let adsenseLoaded = false;
const loadAdsense = () => {
if (adsenseLoaded) return;
adsenseLoaded = true;
const adScript = document.createElement('script');
adScript.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
adScript.setAttribute('data-ad-client', 'ca-pub-xxxxxxxxxxxxxxxx'); // Replace with your publisher ID
adScript.async = true;
document.head.appendChild(adScript);
// Clean up event listeners
['scroll', 'mousemove', 'touchstart'].forEach(evt =>
window.removeEventListener(evt, loadAdsense)
);
};
// Listen for user interaction
['scroll', 'mousemove', 'touchstart'].forEach(evt =>
window.addEventListener(evt, loadAdsense, { passive: true })
);
Method B: Time Delay Execution (Best for WordPress)
If you use WordPress, implementing complex event listeners manually can be tricky. Instead, use a performance plugin to handle the delay.
- Install WP Rocket or Flying Scripts by WP Speed Matters.
- Go to the "Delay JavaScript Execution" settings.
- Add
adsbygoogle.jsto the delay list. - Set the timeout to load only on user interaction.
Preventing Cumulative Layout Shift (CLS)
Delaying AdSense solves your speed problems, but it creates a new one: CLS. When the ad finally loads, it will push your text down the screen.
The Fix: Always wrap your <ins> ad tags in a container with a fixed minimum height (e.g., min-height: 250px;). This reserves the space on the page before the ad arrives, completely eliminating layout shifts.
Final Thoughts
If you rely on AdSense for revenue, lazy loading is no longer just a "nice-to-have" optimization—it's mandatory for passing Core Web Vitals in 2026. Implement these scripts carefully, monitor your ad viewability metrics in the AdSense dashboard, and enjoy your faster website.
Your feedback helps us improve our content for everyone.