Website Development

WordPress JavaScript Optimisation: Defer, Conditional Loading, and INP Improvement

JavaScript is the heaviest performance burden on most WordPress sites. Here is the complete optimisation framework -- from auditing to deferral to...

Athar Ahmad
Reviewed by Athar AhmadFounder & CEO · Written by the SA Solutions team
Published March 22, 2026 Updated October 17, 2026 5 min read
On this page
  1. Why JavaScript matters more than ever for WordPress
  2. Auditing JavaScript on your WordPress site
  3. Method 1 — Defer non-critical JavaScript
  4. Method 2 — Load scripts only where needed
  5. Method 3 — Minify and combine JavaScript
  6. Method 4 — Replace heavy scripts with lighter alternatives
  7. Method 5 — Preload critical scripts
  8. Need JavaScript performance optimisation for your WordPress site?
  9. Frequently asked questions

JavaScript is the heaviest performance burden on most WordPress sites. Here is the complete optimisation framework — from auditing to deferral to replacing heavy scripts.

  • INP — the Core Web Vitals metric most affected by JS
  • Defer — loads JS after render, prevents blocking
  • Asset CleanUp — disables scripts per-page
  • Coverage tool — shows unused JS percentages

JavaScript is typically the heaviest performance burden on WordPress sites. Every plugin that adds scripts, every page builder that loads its framework, and every third-party tool that injects JavaScript contributes to INP (Interaction to Next Paint) and LCP (Largest Contentful Paint) scores. Here is how to audit, reduce, and optimise JavaScript on WordPress.

Why JavaScript matters more than ever for WordPress

Google’s shift from FID (First Input Delay) to INP (Interaction to Next Paint) as a Core Web Vitals metric in March 2024 made JavaScript performance significantly more important for SEO. INP measures how quickly your page responds to every user interaction — not just the first. Heavy JavaScript that blocks the main thread causes poor INP scores even on fast-loading pages.

Metric What JavaScript affects Target
Largest Contentful Paint (LCP) Render-blocking scripts delay first content render Under 2.5 seconds
Interaction to Next Paint (INP) Heavy JS blocks main thread, delaying interaction response Under 200ms
Time to Interactive (TTI) JS execution must complete before page is interactive As low as possible
Total Blocking Time (TBT) Long tasks on main thread block user interaction Under 200ms

Auditing JavaScript on your WordPress site

Run PageSpeed Insights and check Opportunities

PageSpeed highlights specific JS issues: ‘Eliminate render-blocking resources’, ‘Reduce unused JavaScript’, ‘Avoid long main-thread tasks’. Each Opportunity item shows which scripts are causing the issue.

Use Chrome DevTools Performance panel

Record a page load in Chrome DevTools Performance tab. The flame chart shows exactly which scripts take longest to execute. Long Tasks (red diagonal lines) are your highest-priority optimisation targets.

Use Coverage tool to find unused JS

In Chrome DevTools, open the Coverage tab (Ctrl+Shift+P, type Coverage). Load your page and see what percentage of each JavaScript file is actually executed. Files with 70%+ unused JS are candidates for deferred loading or removal.

Check with Query Monitor plugin

Query Monitor’s Scripts panel shows every script enqueued on each page, which plugin or theme enqueued it, and where it loads (header or footer). Identify scripts loading in the header that could be deferred.

Method 1 — Defer non-critical JavaScript

Deferred JavaScript loads after the page has rendered, preventing it from blocking initial page display. Configure deferral in WP Rocket or other caching plugins:

  • WP Rocket: File Optimisation › JavaScript › Load JavaScript Deferred. This adds the defer attribute to all applicable scripts automatically.
  • W3 Total Cache: Minify › JS Minify › Load deferred. Similar functionality to WP Rocket.
  • Manual defer via functions.php: hook the script_loader_tag filter to add defer or async attributes to specific script handles.
  • Always test after enabling defer — some scripts depend on synchronous loading order and break when deferred.

Method 2 — Load scripts only where needed

Most plugin scripts load on every page even when the plugin functionality is only used on specific pages. A contact form plugin loading its validation script on your homepage is waste. Fix this with Asset CleanUp Pro or manual conditional enqueue:

Install Asset CleanUp Pro

Asset CleanUp scans every page of your site and shows which scripts are loaded. You can disable individual scripts on specific pages with a toggle.

Identify scripts not needed on specific pages

A contact form plugin script should only load on your Contact page. A WooCommerce script should only load on shop, product, cart, and checkout pages.

Disable scripts conditionally

In Asset CleanUp, mark scripts as disabled globally and enable only on relevant pages. Or use conditional loading in your plugin or theme: wrap wp_enqueue_script() calls in is_page(), is_single(), or is_woocommerce() checks.

Method 3 — Minify and combine JavaScript

Minification removes whitespace and comments from JS files, reducing file size. Combining merges multiple JS files into one, reducing HTTP requests. Both are available in caching plugins:

  • WP Rocket: File Optimisation › Minify JS files and Combine JS files
  • W3 Total Cache: Minify › JS Minify settings
  • Combining JS is more fragile than minifying alone — test thoroughly after enabling, especially with Elementor, Divi, or other page builders that load many scripts

Method 4 — Replace heavy scripts with lighter alternatives

Some plugins are simply too heavy for what they do. Common replacements:

Heavy solution Lighter alternative Savings
jQuery-based slider/carousel CSS-only carousel or lightweight JS (Swiper.js) 300-500KB removed
Full jQuery UI library Use specific jQuery UI components only, or replace with vanilla JS 100-200KB removed
Full Lodash/Moment.js Use native JavaScript equivalents for date formatting and utilities 50-150KB removed
Heavy social sharing plugin CSS+HTML share buttons with no JS 20-80KB removed
Full FontAwesome Use only the icons you need via SVG sprites 200-400KB removed

Method 5 — Preload critical scripts

For scripts that are critical to your page rendering (your primary theme JavaScript, critical functionality), preloading tells the browser to fetch them earlier in the loading sequence:

Add <link rel='preload' as='script' href='/path/to/critical.js'> to your page head. WP Rocket’s link preloading feature handles this for scripts you designate as critical. Do not preload non-critical scripts — it defeats the purpose.

Need JavaScript performance optimisation for your WordPress site?

Simple Automation Solutions performs WordPress JavaScript audits and implements optimisations that improve INP, LCP, and Core Web Vitals scores for businesses worldwide.

Book a Free Call View Our Work →

Frequently asked questions

How do I know which JavaScript files are causing poor INP scores? +

Use Chrome DevTools Long Tasks API or the Web Vitals Chrome extension. In DevTools, record a page load and user interaction in the Performance panel. Look for Long Tasks (orange bars) that occur during user interactions. Each Long Task shows which script file was executing. The PerformanceObserver API can also log INP events with the associated script, identifying exactly which interaction and which code path is causing the delay.

Will removing jQuery break my WordPress site? +

WordPress includes jQuery by default and thousands of plugins depend on it. Removing jQuery outright will almost certainly break functionality. However, you can improve jQuery performance by loading it in the footer instead of the header (defer it via WP Rocket), ensuring plugins use the WordPress-bundled jQuery rather than loading their own version, and ensuring jQuery Migrate is disabled on production sites (it is only needed for legacy plugin compatibility testing). Modern WordPress development can use vanilla JavaScript for new code, but the existing jQuery dependency is rarely worth removing entirely.

What is the difference between defer and async for JavaScript? +

Both load scripts without blocking HTML parsing. The difference is in execution timing. Async scripts execute as soon as they are downloaded, potentially before HTML is fully parsed — they can arrive and execute in any order. Defer scripts execute after HTML parsing is complete, in the order they appear in the HTML. For WordPress themes and plugins that depend on the DOM being ready before executing, defer is usually the correct choice. Async is better for completely independent scripts like analytics or advertising tags that do not depend on DOM elements.

Athar Ahmad
Athar AhmadFounder & CEO, SA Solutions · Certified Bubble.io Developer

Athar has spent more than 8 years building digital products and leads every SA Solutions project, from Bubble.io apps to AI automation for small and growing businesses. Read our editorial standards.

Other posts

Need help with your website or app?

Book a free 30-minute call and get honest advice and a clear next step.

Book a free callSee our services