Find the right JS files to exclude from minification

JavaScript minification can be quite hard to troubleshoot, especially when you have a lot of files. We describe a process in our doc “Resolving issue with file optimization”, which is essentially a process of elimination. However, sometimes it’s possible to more directly identify and exclude the problematic files.

If you have enabled the Remove Query String option in the Static Files tab, make sure to disable it while troubleshooting. 

In this example, we refer specifically to using the Chrome browser.

1

Open Developer Tools. You do that either by right-clicking and choosing Inspect Element, or at the top of the window go to: View→Developer→Developer Tools

2

Find the red error message indicator on the right-hand side:

3

Click it to open the Console, then click the file referenced in the error notice:

4

This takes you directly to the code in the file that is related to the error. Look for the red underline and copy part of that code:

5

Open a new browser tab and load the un-cached version of the page. You do that by adding ?nocache to the URL—this will load an un-cached, un-minified version of the page. It is necessary in order to find the original URLs of the files.

An un-cached URL would look something like http://example.com/?nocache, or http://example.com/some-page/?nocache.

6

Open Developer Tools, then click the 3 dots on the right side and select Search All Files:

7

Paste the problematic code in the search box and it will locate the file in which that code is found:

8

It’s not possible, unfortunately, to copy the filename from this screen. So to do that, click on the Network tab (reload the page if necessary to pull in the files). Then search for the file in the list:

Once you’ve located the file, right-click on the filename, select Copy, then Copy Link Address.

9

Paste this into the Exclude JS field in the Static Files tab of WP Rocket:

After saving this you can visit your site again, reload the page and check that there are no more JavaScript errors reported in the console.