Skip to content

Optimizing Core Web Vitals with Pagelean

This guide explains how removing unused scripts and stylesheets directly improves Google’s Core Web Vitals (CWV) and speeds up your WordPress site.

The problem: Unused JavaScript and CSS in WordPress

Section titled “The problem: Unused JavaScript and CSS in WordPress”

In standard WordPress sites, plugins tend to load their entire frontend footprint on every URL. Google PageSpeed Insights frequently flags this as:

  • Reduce unused JavaScript
  • Reduce unused CSS
  • Eliminate render-blocking resources
  • Minimize main-thread work

Every extra HTTP request and kilobyte of code forces the browser’s rendering engine to download, parse, compile, and execute scripts before content can be fully painted and made interactive.

  • The bottleneck: Stylesheets linked in the <head> are render-blocking by default. The browser pauses layout calculations until all linked CSS files are downloaded and parsed into the CSSOM.
  • Pagelean solution: Dequeuing unneeded stylesheets (such as form styles or slider CSS on text articles) eliminates render-blocking requests, allowing the browser to paint the primary content element (the LCP image or headline) hundreds of milliseconds earlier.
  • The bottleneck: Excess JavaScript monopolizes the browser’s main thread during initialization. When a visitor taps a button or scrolls, the browser cannot respond immediately, causing high input latency.
  • Pagelean solution: By preventing heavy scripts from executing on pages where their functionality is absent, Pagelean slashes Total Blocking Time (TBT) and ensures the main thread remains idle and responsive to user input.
  • The bottleneck: Unneeded third-party widgets (e.g., social feed plugins, review badges, or dynamic sliders) injecting DOM elements late in the loading lifecycle often push page elements around, generating layout shifts.
  • Pagelean solution: Stripping these scripts and styles from pages where they are not deliberately placed guarantees stable layouts and near-zero CLS scores.

High-impact real-world optimization scenarios

Section titled “High-impact real-world optimization scenarios”
  • The issue: The plugin enqueues its styles and JavaScript on all pages, including blog articles, shop pages, and the homepage.
  • The fix in Pagelean:
    • Create a rule for contact-form-7 (Script) with condition: Except single posts/pages (matching IDs).
    • Enter the ID of your /contact page (e.g., 18).
    • Repeat for contact-form-7 (Style).
  • Result: Saves 2 HTTP requests and ~35 KB of unused assets on 99% of your site’s URLs.

Scenario 2: WooCommerce Cart Fragments on informational pages

Section titled “Scenario 2: WooCommerce Cart Fragments on informational pages”
  • The issue: On sites running WooCommerce alongside a content blog or lead-generation pages, wc-cart-fragments executes an AJAX call on every page to update mini-cart counts.
  • The fix in Pagelean:
    • Create a rule for wc-cart-fragments (Script) with condition: Except single posts/pages (matching IDs) or specific non-commerce post types.
  • Result: Completely eliminates an unnecessary server round-trip on blog reading pages.
Section titled “Scenario 3: Heavy slider and gallery libraries”
  • The issue: Sliders (e.g., Swiper, Slick, Owl Carousel) loaded site-wide even though the carousel is only featured on the homepage.
  • The fix in Pagelean:
    • Create a rule for the slider script with condition: Except single posts/pages (matching IDs) (entering the homepage ID) or use Everywhere except matching IDs.
  • Result: Removes 50 KB to 150 KB of heavy animation JavaScript from your article pages.
  1. Before applying rules: Run a Lighthouse or PageSpeed Insights audit on an article page. Record the LCP time, INP score, and the “Reduce unused JavaScript” payload.
  2. Apply targeted rules in Pagelean.
  3. Purge page cache: If using a caching plugin (e.g., WP Rocket, LiteSpeed, W3 Total Cache) or a CDN (Cloudflare), clear the cache for that specific URL.
  4. Re-run the audit: Confirm that the targeted handles no longer appear in the waterfall chart and that main-thread execution time has dropped.