The Page Optimize plugin is automatically installed on plugin-enabled sites on WordPress.com. This advanced guide explains the steps to exclude specific JavaScript files from being concatenated by the Page Optimize plugin.
This feature is available on sites with the WordPress.com Creator and Entrepreneur plans, and the legacy Pro plan. For sites on the free, Starter, and Explorer plans, upgrade your plan to access this feature.
In this guide
The Page Optimize plugin includes features that may improve how quickly browsers can load your website:
- Concatenate CSS
- Concatenate JavaScript
- Execution timing of non-critical scripts
Please bear in mind that while these optimizations may improve your site’s loading times, Page Optimize is not guaranteed to improve them and should not be considered an alternative to ensuring your code is performant.
The Page Optimize plugin is automatically installed on WordPress.com sites with a plugin-eligible plan. The Page Optimize plugin can be deactivated like any other plugin.
If you notice activating the Page Optimize plugin appears to be negatively impacting your site’s performance, you may perform these debugging steps to identify files to exclude from JS concatenating:
- Deactivate the Page Optimize plugin from Plugins → Installed Plugins.
- Load the problematic page on your website.
- Open your browser’s inspector tool and select the Console tab.
- Look for errors relating to Javascript files (.js). In this example, an error occurred in the
eu-cookie-law-min.js
file:
- Reactivate the Page Optimize plugin from Plugins → Installed Plugins.
- View the source code of the webpage (right-click > View Page Source).
- Find the
data-handle
of the script - Add the
data-handle
in the exclusion list
The data-handle
is the unique slug used by the WordPress software to identify plugins, themes, CSS, and Javascript files. Before you can add something to the exclusion list, you must find out the data-handle
of the Javascript file. To do this, view the source code of the webpage and look for the <script>
tag that contains the data handles. It will look something like:
<script data-handles='mediaelement-migrate,eu-cookie-law-script' type='text/javascript'></script>
Using your browser’s Find tool will make it easier to find the tag. Press Ctrl+F (Windows) or Cmd+F (Mac) on your keyboard and search for <script data-handles
By looking at the tag, you should be able to find the data-handle
of the offending script. In our example, it’s eu-cookie-law-script
.
The exclusion list is a list of data-handles that are ignored by the plugin, meaning they are not going to be concatenated.
To add something to the exclusion list:
- From your site’s dashboard, navigate to Settings → Performance (or Jetpack → Settings → Performance if using WP-Admin).
- Under Performance & speed, click “Optimize JS and CSS for faster page load and render in the browser.”
If you do not see the link to “Optimize JS and CSS…” make sure the Page Optimize plugin is active by visiting Plugins → Installed Plugins.
- In the space under “Comma separated list of strings to exclude from JS concatenating:” enter the
data-handle
preceded by a comma:
- Click the “Save Changes” button.
If the above steps do not help, try the following:
- Turn off other optimization plugins that may be in conflict with Page Optimize
- Turn off optimization settings provided by your theme