Dev.to WebDev 🛠 Dev 👁 0 📖 2 min read

Catch a Core Web Vitals regression the day you deploy (Python and a cron job)

A slow page rarely announces itself. Someone adds a chat widget, the mobile score drops from 90 to 62, and you find out three weeks later from Search Console. A small scheduled audit of your ten most important URLs fixes

A slow page rarely announces itself. Someone adds a chat widget, the mobile score drops from 90 to 62, and you find out three weeks later from Search Console. A small scheduled audit of your ten most important URLs fixes that. This is how I set it up.

Audit the pages that matter

I use a hosted Actor I maintain on Apify (Bulk PageSpeed & Core Web Vitals Audit). With pip install apify-client:

from apify_client import ApifyClient

client = ApifyClient("<YOUR_APIFY_TOKEN>")
run = client.actor("fjordlabs/pagespeed-audit").call(run_input={
    "urls": ["example.com", "example.com/pricing", "example.com/blog"],
    "strategies": ["mobile", "desktop"],
    "categories": ["performance", "seo"],
    "maxOpportunities": 3,
    "alertBelowPerformanceScore": 80,
})

rows = list(client.dataset(run.default_dataset_id).iterate_items())
bad = [r for r in rows if r.get("alert")]

alertBelowPerformanceScore sets alert: true on any page under your threshold, so you don't need to write the comparison yourself.

Say what to fix, not just that it's slow

Each row has the Lighthouse scores, lab metrics (lcpMs, cls, tbtMs) and the top opportunities with estimated savings:

for r in bad:
    print(f"{r['url']} ({r['strategy']}): performance {r['scores']['performance']}, LCP {r['lab']['lcpMs']} ms")
    for o in r["opportunities"]:
        print(f"   - {o['title']}: ~{o['savingsMs']} ms")

Lab numbers vary a little between runs. Look for a drop of 10 points or more, not 2.

Page data versus origin data

fieldDataPage is real-user data for that exact URL, but Google only has it for popular pages, so it is often null. fieldDataOrigin covers the whole site, and coreWebVitalsPassed tells you whether the pass/fail verdict came from real users. Don't mix the two in one chart.

Run it after each deploy

Schedule the Actor in Apify (daily is plenty), or call it from your CI job after the deploy step and fail the job if bad is not empty. For a scheduled run, add Apify's Slack or webhook integration instead and you get a message only when something is red.

Each audit costs $0.004 (one URL on one device), so 10 URLs on mobile and desktop is 20 audits, or about 8 cents per run. Failed audits are free.

Disclosure: I built and maintain the scraper. Questions and feature requests welcome in the comments. Links to Apify include my referral code.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.