How to fix the “jQuery is not defined” error
Something has broken on your site, you’ve checked your browser console for errors and found the following error:
jQuery is not defined
The error means that jQuery is required by another script, but due to the optimization, it’s not available when that initial script runs, and therefore triggers an error.
First check that this error is caused by WP Rocket.
Load your page while bypassing WP Rocket, by adding
?nowprocket to the URL (e.g.
example.org?nowprocket), and check if the error exists there.
The error isn’t there on ?nowprocket
If the error shows up only when WP Rocket is active on the page, it’s related to one of these options on the File Optimization tab:
jQuery is not added here by default, but if you have customized the list, you should remove any entry containing jQuery:
In the event that you are not using the version of jQuery loaded by WordPress, but are using one hosted by a 3rd party, you can find the right file to exclude by doing the following:
- Load your site while bypassing WP Rocket, adding
?nowprocketto your URL.
- Click the Network tab in the Developer tools of your browser
- Filter for
jquery.min.js, and if that doesn’t yield a result, try
- Copy the URL and paste it into the exclusion field in WP Rocket
(This pattern will catch variations on the filename)
After applying these exclusions, save the changes and the problem should be resolved.