Home / Fix guides / Long main-thread tasks blocking interaction / WordPress

WordPress fix guide

How to avoid long main-thread tasks on WordPress

A long task is any piece of JavaScript that keeps the browser busy for more than 50 milliseconds, so taps and clicks feel stuck. On WordPress the cause is almost always plugins, page builders or third-party scripts, and you can usually fix it without writing code.

When a visitor taps a menu and nothing happens for a moment, the browser's main thread is usually busy running JavaScript. Tests like Lighthouse and PageSpeed Insights report this as "Avoid long main-thread tasks" or "Reduce JavaScript execution time". It hurts the Interaction to Next Paint (INP) score in Core Web Vitals. WordPress itself loads very little JavaScript on the front end. The weight comes from what you add on top.

For the general explanation, see long JavaScript tasks. This page covers what is specific to WordPress.

Why WordPress sites get long tasks

The usual causes, roughly in order of how often they appear:

  • Page builders and theme bundles that load large scripts on every page (Elementor, Divi and similar, depending on your setup)
  • Sliders, popups, animation libraries and "mega menu" add-ons
  • Analytics, ad, chat, heatmap and social scripts, often added through Google Tag Manager
  • WooCommerce extras such as cart fragments, reviews or product filters
  • Several plugins each loading their own copy of the same library

Step by step: find and fix the cause

  1. Take a backup, and use a staging site if your host offers one. Most hosts provide staging under their own dashboard, not inside WordPress. You will be changing how scripts load, and a backup lets you undo anything.
  1. Measure the page that matters. Run your home page and one busy page through PageSpeed Insights. Open the "Avoid long main-thread tasks" item and note the script URLs listed. A URL containing /wp-content/plugins/plugin-name/ tells you which plugin it belongs to. /wp-content/themes/ points to your theme. Anything from another domain is a third-party script.
  1. Look closer in Chrome. Open the page, press F12, go to the Performance tab, record while you reload and tap a few things. Tasks marked with a red corner are long tasks. Click one and the Bottom-Up or Call Tree view shows which script file ran.
  1. Match scripts to plugins. The free Query Monitor plugin has a Scripts section that shows which plugin or theme added each script on the current page. Install it only while you investigate, then deactivate it.
  1. Remove what you do not need. Go to Plugins in the dashboard and deactivate anything unused. Then check each remaining plugin's settings for options that load its scripts on every page. Many have a setting to load only where needed.
  1. Load scripts only on pages that need them. A contact form script does not need to run on every blog post. Tools such as Asset CleanUp or Perfmatters let you switch scripts off per page or per post type. Change one thing at a time and check the page afterward, because turning off the wrong script can break a menu or form.
  1. Delay or defer the rest. Caching and optimization plugins such as WP Rocket (under File Optimization, look for "Delay JavaScript execution" and "Load JavaScript deferred") or Autoptimize can postpone scripts until the visitor interacts or the page has loaded. Delaying works well for chat widgets, analytics and popups. It can break sliders and menus, so test them. If you or a developer write code, wp_enqueue_script() supports a strategy of defer or async in WordPress 6.3 and later.
  1. Deal with third-party scripts. Remove tags in Google Tag Manager that nobody uses, and load chat or review widgets after interaction. More on this in third-party scripts slow your site.
  1. Consider a lighter replacement. If one plugin or theme feature is responsible for most of the blocking time, look for a lighter alternative, or ask your developer to replace it with plain CSS or a smaller script. Slider and animation add-ons are common candidates.
  1. Re-test. Clear your cache, then run the same pages through PageSpeed Insights again. Test on mobile, where the processor is slower and long tasks show up most. Click through menus, forms, the cart and checkout by hand.

What WordPress cannot do for you

WordPress has no built-in setting that splits up long tasks. If a theme or plugin ships one huge script, you can delay it, remove it or replace it, but breaking it into smaller pieces needs changes in its code. That is a job for the plugin author or a developer. Editing plugin files directly is not safe, since updates overwrite your changes.

Keeping it fixed

Long tasks tend to come back when someone installs a new plugin or adds a new marketing tag. Re-test after every major plugin or theme change. SiteMonday checks speed and Core Web Vitals in week 4 and lists the findings in a ranked fix list, but the changes themselves are up to you or your developer.

Not on WordPress? Read the general guide to long main-thread tasks blocking interaction, or the guide for React, Next.js, Shopify, Wix, Google Tag Manager, Vercel.

Questions

Which WordPress plugin causes long main-thread tasks?

There is no single culprit. The PageSpeed Insights report lists script URLs, and a path like `/wp-content/plugins/name/` shows which plugin owns it. Query Monitor can confirm this on the page.

Will a caching plugin fix long tasks by itself?

Not usually. Caching makes the server respond faster but does not reduce JavaScript. You need the delay, defer or per-page script options, and a lighter set of plugins.

Is it safe to delay JavaScript in WordPress?

Mostly, but test afterward. Sliders, mobile menus, forms and checkout pages are the parts most likely to break, so exclude those scripts if something stops working.

Does Elementor or Divi cause long tasks?

Page builders add JavaScript and can contribute, especially with many widgets or animations on one page. Using fewer effects and turning on the builder's own performance or script-loading options often helps.

Can I fix this without a developer?

Often yes: removing unused plugins, disabling scripts per page and delaying scripts through an optimization plugin need no code. A developer is only needed when one script is too large and has to be replaced or rewritten.

More WordPress fixes