Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared Managed Cloud India
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Best lists Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Plugin how-tos · Guide

How to Exclude Scripts from WP Rocket Delay JavaScript

Short answer

To exclude a script from WP Rocket Delay JavaScript Execution, go to Settings → WP Rocket → File Optimization and add the file path, file name, or keyword to the Excluded JavaScript Files box, one entry per line. You can also tick a one-click exclusion box for a known plugin, theme, or service, or add the nowprocket attribute to the script tag. Save the page and clear the cache, then check the page to confirm the script runs at once.

Key takeaways

  • Delay JavaScript Execution holds scripts back until a visitor moves the mouse, scrolls, touches the screen, or presses a key.
  • Add exclusions in Settings → WP Rocket → File Optimization, in the Excluded JavaScript Files text area, one entry per line.
  • One-click exclusion boxes cover known plugins, themes, and services, and they are the fastest option when your tool is listed.
  • Safe Mode excludes almost all scripts from delay, so use it only as a short-term fix while you find exact exclusions.
  • Too many exclusions can bring back the Reduce unused JavaScript audit in PageSpeed, so keep the list as short as you can.
  • Use the browser console to find the exact file: a ReferenceError names the missing function, and ?nowprocket shows the unoptimized page.

What is a WP Rocket Delay JavaScript exclusion?

A WP Rocket Delay JavaScript exclusion is a file, keyword, or pattern you list so WP Rocket runs that script at once instead of holding it until a visitor interacts with the page.

Delay JavaScript Execution holds back JavaScript files and inline scripts until a visitor moves the mouse, scrolls, touches the screen, or presses a key, according to the WP Rocket docs. The goal is to let the page render first and run scripts later.

An exclusion is the exception to that rule. You add it when a script must run on load for the page to work, such as the code behind a menu, a slider, or a checkout form. The excluded script loads at once, while every other script stays delayed.

One fact worth knowing: the delay applies only on cached or optimized pages, so a page served without cache runs scripts at once. WP Rocket also excludes the wp-embed-min file by itself, so it loads right away even with delay turned on.

Delay JavaScript Execution is one of the features in the premium WP Rocket plugin, covered in the WP Rocket review. It is a caching plugin, so its delay feature only has an effect on pages that WP Rocket caches.

When should you exclude a script from Delay JavaScript?

Exclude a script when a page element stays broken or hidden after a visitor has already clicked, scrolled, or waited a few seconds.

WP Rocket's own troubleshooting guide splits delay problems into two kinds. A layout or functionality problem means an element never works, even after interaction, and those scripts should be excluded. An aesthetic-only problem means an element appears late but still works, and there you choose between speed and polish.

Common signs that an exclusion is needed include a mobile menu that never opens, a slider that stays blank, a form that never submits, or a checkout button that does nothing. If the problem goes away when you turn Delay JavaScript Execution off, delay is the cause.

You should not exclude scripts just because a page feels slow. Each exclusion trims the speed gain, so start with the smallest fix: one file, then check the page again. Page builders add their own scripts too, so if your site uses Elementor, the Elementor performance settings guide covers its script options.

Where do you add exclusions in WP Rocket?

You add exclusions in WP Rocket → File Optimization, in the Delay JavaScript Execution area of the JavaScript Files section.

  1. Open your WordPress dashboard and go to Settings → WP Rocket.
  2. Click the File Optimization tab.
  3. Scroll to the JavaScript Files section and find Delay JavaScript Execution.
  4. Make sure the Delay JavaScript Execution checkbox is ticked.
  5. Use the One-click exclusions boxes or the Excluded JavaScript Files text area below it.
  6. Click Save Changes at the bottom of the page.
  7. Clear the WP Rocket cache so the new settings reach visitors.

The File Optimization tab holds the rest of WP Rocket's JavaScript settings too. Keep the Combine JavaScript files option off while delay is on, because WP Rocket disables it itself to keep scripts in the right order. For the full setup, see the guide on how to configure WP Rocket for Core Web Vitals.

How do you use the One-click exclusions?

One-click exclusions are tick boxes for known plugins, themes, and services, and they are the fastest way to exclude a script without typing a file path.

WP Rocket shows these boxes in the One-click exclusions area under Delay JavaScript Execution. Each box covers the scripts of one plugin, theme, or service, so you tick the box that matches the tool that broke. Save the page and clear the cache, then check the page again.

Use this method first. It is the simplest option, and it avoids typing errors that come with manual paths. If the plugin or service you need is not listed, move on to the manual text area instead.

Some vendors publish their own exclusion lists for their tools. The Search & Filter docs, for example, list its app.js file, its component files, and window.searchAndFilter variables to add when its fields fail to show, in their WP Rocket guide.

How do you add a manual exclusion in Excluded JavaScript Files?

You add a manual exclusion by typing a file URL, a file name, or a keyword on its own line in the Excluded JavaScript Files text area.

  1. Find the file you need, using the console method below.
  2. Go to Settings → WP Rocket → File Optimization.
  3. Scroll to Delay JavaScript Execution and find the Excluded JavaScript Files text area.
  4. Type the file path or keyword, one entry per line.
  5. Click Save Changes, then clear the cache.

A full path looks like /wp-content/themes/your-theme/assets/js/nav.js. A keyword works too: typing complianz excludes every script whose name or path holds that word. The Complianz docs show this with the keywords complianz and cmplz plus the file complianz-gdpr/cookiebanner/js/complianz.min.js, in their guide to excluding Complianz scripts.

For an external script, use the file name and part of its path, not the domain. WP Rocket warns that the domain can stop matching once Minify JavaScript files hosts the script on your own server. Its example excludes ads.com/ads-folder/script.js by entering /ads-folder/script.js.

What exclusion patterns can you use?

Patterns let you exclude a whole folder or every inline script with one line, instead of listing each file by name.

PatternWhat it excludes
/plugins/(.*)All scripts in the plugins folder
/themes/(.*)All scripts in the themes folder
/wp-includes/(.*)All scripts in the WordPress core folder
/uploads/(.*)All scripts in the uploads folder
/cache/min/(.*)All scripts in the minified cache folder
\(All inline scripts
\{All inline scripts

These patterns come from the WP Rocket troubleshooting guide, which lists them as the main patterns for exclusions. Folder patterns are broad, so use the narrowest one that fixes the problem.

Excluding a whole folder trades speed for function, and WP Rocket warns that too many exclusions can bring back the Reduce unused JavaScript audit in PageSpeed.

Some patterns are not allowed. WP Rocket removes invalid patterns at once and shows the notice "WP Rocket: The following patterns are invalid and have been removed", so check for that message after saving.

Two more details from the same guide: jQuery and jQuery Migrate should be excluded together, using one pattern that covers both file names, and WP Rocket also offers a helper plugin that excludes scripts only on chosen URLs instead of site-wide.

How do you find the exact script to exclude?

You find the script by reading the JavaScript errors in your browser console, then matching the missing name to the file that defines it.

  1. Open the broken page and open Developer Tools → Console.
  2. Look for errors such as Uncaught ReferenceError: example_code is not defined, which means a function was needed before its delayed file ran.
  3. Open the same page in a second tab with ?nowprocket at the end of the URL to bypass WP Rocket.
  4. In that tab, open the Search tab in Developer Tools and search for the missing name.
  5. The search lists every script that uses or defines that name.
  6. Add those files to the Excluded JavaScript Files box, save, clear the cache, and check the page.

WP Rocket's troubleshooting guide describes this console method step by step. You can also work by context: inspect the broken element, note its class, then search for that class in the unoptimized page to find the linked script.

If new errors appear after your first fix, run the same method again, since some scripts depend on the file you just excluded.

A third method is the process of elimination: exclude files one at a time until the page works, then remove exclusions one by one to keep only the ones that matter.

This takes longer, so use the console first. Fix any errors that already exist in the console before you start, since WP Rocket notes that old errors can muddy the results.

What is Safe Mode for Delay JavaScript Execution?

Safe Mode is a WP Rocket option that excludes almost all of your site's scripts from delay in one click, and it is meant as a short-term fix only.

Turning it on excludes scripts under the /wp-content/ and /wp-includes/ folders, the jQuery and jQuery Migrate libraries, and inline JavaScript added with the wp_add_inline_script() WordPress function. In plain terms, most of your site's JavaScript runs at once again, so delay problems should stop.

The cost is speed. WP Rocket states that Safe Mode takes away most of the performance gain from Delay JavaScript Execution, and it calls the option a last resort for cases where finding exclusions gets too complex.

Use it to confirm that delay is the cause, then replace it with exact exclusions found through the console method.

How do you exclude a script with code?

You exclude a script with code by adding the nowprocket attribute to its script tag, which tells WP Rocket to leave that script alone.

For an external file, add data-nowprocket to the opening script tag, before the src attribute that points to the file. For an inline script, add the same attribute to its opening tag, like this:

script data-nowprocket
function myFunction() {
// Your code
}

WP Rocket also treats the word nowprocket inside a script, such as in a comment, as an exclusion trigger. The WP Rocket docs show both forms, and the troubleshooting guide adds that data-nowprocket works as an attribute name too.

This method suits developers who control the theme or plugin code. If you only manage the site through the dashboard, the settings box is the better route. Either way, clear the cache after the change.

How do you check that your exclusions worked?

Check by loading the page without touching it: only the excluded scripts and wp-embed-min should run before your first interaction.

WP Rocket's own check works like this. Load a page and watch the network tab: only one JavaScript file loads at first, since wp-embed-min is excluded by itself. Move the mouse over the page, and the rest of the delayed scripts load.

With your exclusion in place, the excluded file should load at once, before any mouse move.

You can also inspect a script in the page source. Delayed scripts carry the type text/rocketlazyloadscript and a data-rocket-src attribute, while an excluded script keeps its normal form. Each script also gets a data-rocket-status value of executed when it ran as planned, or failed when it did not run.

Then run a fresh PageSpeed check. Delay JavaScript Execution can help the Remove unused JavaScript, Minimize main thread work, Reduce JavaScript Execution time, Total blocking time, and First contentful paint audits, according to the WP Rocket docs.

A long task is any main-thread task longer than 50 milliseconds, and Total Blocking Time adds up the part of each long task past that 50-millisecond line, as web.dev explains.

If your exclusions are too broad, those audits get worse again, so keep the list short. For wider speed work, see the guide on how to speed up WordPress.

What mistakes should you avoid?

The biggest mistakes are excluding too much, using the wrong match, and leaving Safe Mode on after the fix.

  • Excluding whole folders when one file would fix the problem, since each extra exclusion cuts the speed gain.
  • Using a domain to exclude an external script, since Minify JavaScript files can host that script on your own server and break the match.
  • Leaving Safe Mode on for weeks instead of replacing it with exact exclusions.
  • Skipping the cache clear after saving, which leaves visitors on the old settings.
  • Mixing Delay JavaScript Execution with another plugin's JavaScript combination, since WP Rocket warns that other combination tools must be off to avoid display problems.
  • Forgetting that a theme or plugin lazyload feature can clash with delay: WP Rocket notes that some themes run their own image lazyload, and images may stay hidden until interaction. Its guide suggests using WP Rocket's LazyLoad instead, and it already excludes the lazyload features of Smush and EWWW.
  • Delaying a script that a checkout or tracking tool needs at once, since a visitor who never clicks may never trigger it.
  • If breakage started with WP Rocket 3.18.1, update to 3.18.3 or later, since most of the layout issues from the 3.18.1 delay update were fixed there.
  • Ignoring Internet Explorer 11: Delay JavaScript Execution does not work with it, and those visitors are sent to an uncached copy of the page with ?nowprocket=1 added to the URL.

Frequently asked questions

Can I exclude a script only on some pages?

Yes. The Excluded JavaScript Files box applies site-wide, but WP Rocket offers a helper plugin that excludes scripts from Delay JavaScript Execution only on chosen URLs. Use that when a script breaks one page type, such as a checkout or a landing page, but works fine when delayed elsewhere. You still need to know the exact file path or keyword first, so find it with the console method before setting up the helper plugin.

Why does my menu still not work after I excluded its script?

The menu script may depend on another file that is still delayed, such as jQuery. Open the console again and look for new errors, then exclude the missing file too. Also check that you saved the settings and cleared the cache, since old cached pages will not use the new exclusion list. If the problem persists, turn on Safe Mode briefly: if the menu works then, delay is still the cause and more files need excluding.

Does Delay JavaScript Execution work on every page?

No. It applies only on cached or optimized pages, so a page served without cache runs its scripts at once. It also does not work with Internet Explorer 11: visitors on that browser are sent to an uncached copy of the page with ?nowprocket=1 added to the URL. On some pages, a PHP backtrack limit error can stop the delay from applying at all, and the fix is to raise pcre.backtrack_limit in wp-config.php or ask your host to raise it.

What happens if I exclude too many scripts?

The speed gain shrinks. WP Rocket warns that excluding too many scripts can bring back the Reduce unused JavaScript audit in PageSpeed, since those scripts load at once again instead of waiting for interaction. In the worst case, Safe Mode removes most of the benefit of the feature entirely. Keep the list short: exclude only the files that fix a real break, and remove exclusions one by one to check each one is still needed.

Do I need to clear the cache after adding an exclusion?

Yes. WP Rocket serves cached pages to visitors, and those cached copies were built with the old exclusion list. Clear the cache after every change to the exclusions, then load the page in a fresh browser tab and check the element that was broken. If you use a CDN or a second caching layer, clear that too, or the old page may keep showing.

Can I exclude inline scripts from Delay JavaScript Execution?

Yes. You can add the patterns \( and \{ to the Excluded JavaScript Files box to exclude all inline scripts, or add the data-nowprocket attribute to a single inline script tag. Safe Mode also excludes inline JavaScript added with the wp_add_inline_script() WordPress function. Excluding all inline scripts is a broad fix, so use it only when a specific inline script is the problem and you cannot target it alone.

Sources

  1. Delay JavaScript execution WP Rocket Knowledge Base
  2. Troubleshoot Delay JavaScript execution issues WP Rocket Knowledge Base
  3. Total Blocking Time (TBT) web.dev
  4. Excluding Complianz Scripts and CSS from WP Rocket, LiteSpeed, and Other Caching and Optimization Plugins Complianz
  5. WP Rocket - Search & Filter Pro Search & Filter

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

WPLegible editors

Researched from the primary sources listed above and checked against our editorial rules. About the site · How we test