Table of Contents
Google is adding a new insight audit to its speed testing tools that looks for duplicated JavaScript on websites. Duplicated code is a performance issue because downloading and executing it increases page size and loading time, hurting the user experience in the process.
To help you avoid that, this article covers exactly what it means when your site receives this warning, how JavaScript can end up duplicated, how it affects your site, and ways to address it.
TL;DR Duplicated JavaScript insight In a rush and just want the gist? No worries, we’ve got you covered: ✅ Duplicated JavaScript occurs when the same script loads more than once on a web page—often due to overlapping plugins, themes, or manual script calls. It bloats your site, increases loading time, negatively impacts Core Web Vitals, and can cause bugs or visual glitches. ✅ To avoid it, always enqueue scripts properly using WordPress functions like wp_enqueue_script() to manage dependencies, ensure the right loading order, make it easier to dequeue or override scripts, and simplify debugging and maintenance. ✅ You can check for duplicates using PageSpeed Insights, browser developer tools, or plugins like Query Monitor. ✅ De-duplicate JavaScript on your site through plugin settings, by manually deleting overlapping calls, using wp_dequeue_script() and wp_deregister_script(), or a plugin like Asset CleanUp. ✅ Optimize JavaScript that remains on your site to further enhance performance. Combine, minify, delay, and defer code, enable browser caching and use a Content Delivery Network (CDN). Use WP Rocket to automate many of these steps or implement them with a few clicks. |
What Does the Warning “Duplicated JavaScript” Mean?
From October 2025, when you test a web page in Google Lighthouse or PageSpeed Insights, you may see a warning that says Duplicated JavaScript.

In fact, you can encounter it even beforehand if you click the Try Insights button appearing on the results page.

It means a significant chunk of JavaScript code loads on the same page more than once. This can happen for several reasons:
- Plugins or themes installed on your site separately load the same library or script, e.g. jQuery.
- Your site calls the same file from slightly different URLs, e.g. https://example.com/script.js and https://example.com/script.js?v=1.2.
- It can also happen because you are loading a file from two locations, such as locally and from a CDN.
There is already an audit in Google Lighthouse/PageSpeed Insights looking for duplicated JavaScript. It may display the message “Remove duplicate modules in JavaScript bundles.”

The new duplicated JavaScript insight audit will replace it.
Why It’s Important to Get Rid of Duplicated JavaScript
Every bit of code browsers must download and parse makes a website appear slower for visitors. It leads to extra HTTP requests, more bandwidth, and higher Total Blocking Time (TBT).
That, in turn, affects the user experience as well as Core Web Vitals, such as Largest Contentful Paint (LCP) and Interaction to Next Paint (INP) — all of which affects your performance in search rankings.
If you force browsers to do this work more than once for the same code, you impede the loading process and hurt your site without any benefit for your site or visitors.
In addition, doubling up the same JavaScript code can also cause bugs like unpredictable behavior, JavaScript errors, UI glitches, or plugin conflicts, further interrupting the user experience.
How to Solve Duplicated JavaScript Problems Manually
Because of their potential negative impact, from here on out, we will deal with how to correct duplicated JavaScript problems on your WordPress site. First manually, so you understand the mechanics, and after that using plugin options as well.
1. Properly Enqueue Scripts in WordPress
WordPress has a dedicated function to add JavaScript to websites: wp_enqueue_script(). Here’s how to use it:
function mytheme_enqueue_scripts() {
// Register the script
wp_enqueue_script(
'my-custom-script', // Handle (name)
get_template_directory_uri() . '/js/custom-script.js', // Script URL
array('jquery'), // Dependencies
'1.0.0', // Version
true // Load in footer
);
}
add_action('wp_enqueue_scripts', 'mytheme_enqueue_scripts');
When you want to include scripts on your site make sure to use this function instead of hardcoding them into your theme. wp_enqueue_script() allows you to define dependencies to ensure the right loading order, and tracks which scripts have already been registered and loaded.
Using it also makes it easier to dequeue or override scripts (more on that soon). Plus, it simplifies debugging and maintenance by centralizing all script loading in one location (such as functions.php or a custom plugin).
Finally, it has functionality to improve performance, by allowing you to load JavaScript in the footer or loading it with defer and async. In short, it’s “the WordPress way” to include JavaScript on your site.
To make sure it can do its job:
- Define script dependencies explicitly using the $deps parameter.
- Use versioning in the $ver parameter to help with browser caching and avoid confusion from query string variations.
- Register scripts with wp_register_script() before enqueueing them to improve dependency management and prevent duplication.
💡 For simpler use cases, like adding analytics tracking code to your site, you can also use hooks like wp_head() and wp_footer(). More on that in our dedicated article on how to add JavaScript to WordPress. |
2. Find Duplicated Scripts on Your Site
What’s really helpful about Google’s insight audit is that it not only tells you when there is a problem with duplicated JavaScript on your site, but also which scripts are causing it. That way, you know exactly where to start to solve your duplication problems.
However, that’s not the only way to spot JavaScript loaded more than once. You can also open your browser developer tools, inspect your website and go to the Network tab. Reload the page and filter by “JS” to see all JavaScript loading on your site.

Look for files with the same name loaded more than once, possibly from different sources or with different query strings.
In addition, there’s the Query Monitor plugin, which visualizes which website scripts are enqueued by which plugin or theme.

Finally, if you want to be really hands-on, view the page source of your site, search for “<script>” markers and identify repeated URLs that way.

3. De-Duplicate JavaScript on Your Site
Finding scripts is only the first step; your main task is to stop them from loading more than once.
If you find that the call for duplicated JavaScript is hardcoded into your site, for example in header.php, you can simply delete it where it occurs (be sure to use a child theme if that means editing your main theme files). Same if your problematic code is enqueued from the functions.php file or from a custom plugin.

In case the duplicated JavaScript is coming from a plugin or other third-party source and has been properly enqueued, you can stop it from loading using the wp_dequeue_script() function.
All you need to know to use it is the script handle (name). You can find that out from the original call or via the Query Monitor plugin.

Here’s how to use it:
function mytheme_dequeue_scripts() {
// Remove a previously enqueued script by its handle
wp_dequeue_script('my-custom-script');
}
add_action('wp_enqueue_scripts', 'mytheme_dequeue_scripts', 100);
💡 Make sure to set a priority of 100 or higher when dequeuing so that your code runs after the function that enqueues your scripts. If you want to completely remove them, follow up with wp_deregister_script().
Again, avoid making changes like this in your main theme—use a child theme or custom plugin for it so you don’t lose changes to a theme update. You can also use conditional tags like is_page(), is_front_page() if necessary.
4. Optional: Optimize JavaScript
While you are in the process of improving the JavaScript situation on your website, you may also consider optimizing all the code that stays on your site. This doesn’t help with duplicated JavaScript but generally improves performance.
It’s also helpful if, for some reason, you are unable to de-duplicate your JavaScript. At least it will let you mitigate some of the speed issues that repeated code introduces.
The following options are available to you:
- Remove unused JavaScript: That means eliminating code that doesn’t do anything. What doesn’t load can’t slow down your website. Easy.
- Combine scripts: This reduces the number of HTTP requests the browser makes, speeding up the loading process.
- Minify JavaScript: Shrinks file size by stripping out whitespace, comments, and other formatting that makes code more human-readable but isn’t needed to execute it. Smaller files mean faster downloads and thus faster page loading.
- Use async or defer for non-critical scripts: This is also called eliminating render-blocking resources. The two attributes delay JavaScript execution and load it in the background to avoid blocking the browser from rendering the page.
- Delay JavaScript execution: Loads scripts only after a user interaction like scrolling or clicking. This improves the initial page load speed because it skips over non-essential JavaScript.
- Enable browser caching: By setting correct HTTP headers, you can tell browsers to save copies of your JavaScript files locally and load them from the hard drive on repeat visits. This way, your pages will load faster for returning visitors.
- Use a Content Delivery Network (CDN): By placing copies of your website files in a global network of servers, visitors can download them from the nearest location and reduce the transmission time.
Again, while this doesn’t do anything about duplicated JavaScript directly, it lessens the overall impact the JavaScript on your website has on its loading speed.
Addressing “Duplicated JavaScript” With a Plugin
If the above seems like a stretch for your skill level, you can also improve your site with the help of WordPress plugins.
1. Dequeue Duplicate Scripts
For one, you can use a plugin like Asset CleanUp to manage and unload JavaScript files on a per-page or global basis.
Both in the plugin settings and at the bottom of the WordPress editor, the plugin gives you a list of JavaScript and CSS files that load on your different pages and content types and where they come from. You then have the ability to unload them.

Look for scripts with the same filename or library (e.g., multiple jquery.js entries) and remove what you don’t need to stop duplicated JavaScript from occurring.
2. Optimize JavaScript Using WP Rocket
After dealing with scripts that load more than once, you can optimize the remaining JavaScript using a performance plugin like WP Rocket.
The plugin minifies JavaScript by default, and lets you combine, delay, defer, and asynchronously load any scripts on your WordPress site by simply checking a few boxes in the File Optimization menu.

Aside from that, WP Rocket automatically implements a number of performance improvements in the background, such as:
- Caching, including a separate mobile cache
- Preloading cache and links
- Critical image optimization to improve Largest Contentful Paint
- Automatic lazy rendering to load elements high up on the page faster
As a matter of fact, simply installing and activating the plugin applies 80% of performance best practices to your site, making it faster automatically. If that isn’t enough, you have many other features you can activate to increase your site speed, like:
- Lazy loading for images, including CSS backgrounds, videos, and iframes
- Preloading external files and fonts
- Database optimization
Wrapping Up
Duplicated JavaScript is a common but avoidable performance issue. It often results from themes, plugins, or manual script insertions loading the same library multiple times.
Duplicate code can negatively impact Core Web Vitals, SEO, and user experience, which is why it’s getting its own insight audit in Google’s speed testing tools. The way to avoid it is by properly enqueuing any scripts present on your site and making a concerted effort to find and de-duplicate those that load more than once. This involves a bit of detective work but it is worth it.
Besides that, you can further improve JavaScript handling on your site by optimizing the code that remains on it. If you need help with the implementation, try WP Rocket risk-free for 14 days and see an instant boost to your site’s performance.