Minify JavaScript makes your script files smaller by removing whitespace and comments. Combine JavaScript merges several script files into fewer files. Minifying is a safe, small win for most sites. Combining can break scripts and rarely helps on modern hosting, so test it carefully.
Available in: Powered Cache (free)
Where to find it: Powered Cache → File Optimization → JavaScript
How JavaScript optimization works #
Powered Cache processes scripts that themes and plugins load the WordPress way (enqueued scripts), and only .js files stored on your own site. These scripts are never minified, and all of them except .min files are also left out of combining:
- Scripts from other domains, such as analytics, maps or payment scripts.
- Files whose name already contains
.min(they are not minified again, but can still be combined). - Scripts that match Excluded JavaScript Files.
- Inline
<script>blocks and scripts written directly into theme templates.
Optimized files are created on the first request, saved in wp-content/cache/min/ and removed when you clear all caches. They are served through the Powered Cache file optimizer, or through /_static/??… URLs when File Optimizer Rewrite Rules are on.
Set up JavaScript optimization #
- Go to Powered Cache → File Optimization.
- In the JavaScript group, turn on Minify JavaScript.
- Leave Combine JavaScript off unless your site runs on HTTP/1.1 and you can test it well.
- Click Save Settings and clear all caches.
- Test menus, sliders, forms, the cart and checkout. Open the browser console and look for JavaScript errors.
Settings #
Minify JavaScript #
Reduces the size of each local script before delivery. Default: off. Apply Recommended Settings turns it on, unless Autoptimize, Perfmatters or PhastPress is active.
Combine JavaScript #
Merges local scripts into fewer files. Default: off. Recommended setup keeps it off.
Powered Cache keeps the original loading order and combines only scripts that follow each other. A script that cannot be combined stays in its place and starts a new group. To avoid breaking dependencies, Powered Cache does not combine:
- Scripts that have inline code attached before or after them, or JavaScript translations.
- WordPress’s React and ReactDOM scripts.
- External scripts and excluded scripts.
When Minify JavaScript is also on, the combined file is minified too. Combining has the same trade-offs as for CSS: on HTTP/2 and HTTP/3 the number of files matters little, pages with different scripts produce different bundles, and an update to one script forces visitors to download the whole bundle again. In addition, an error in one script can stop the code after it in the same file from running. See When combining helps, and when it hurts.
Excluded JavaScript Files #
Keeps matching scripts out of both minifying and combining. Default: empty. Enter one rule per line. Each rule is compared with the script URL and matches when it appears anywhere in it.
jquery.js: a part of the file name or path./wp-content/plugins/my-form/*: every script of a plugin.*matches any text./plugins/(shop|cart)-addon/: a regular expression.
A line that is not a valid regular expression is matched as plain text. These exclusions do not affect Defer JavaScript or Delay JavaScript, which have their own exclusion lists.
Turn off JavaScript optimization for one page #
In the post editor, open the Powered Cache panel and check Disable JS optimization. That post is served without JavaScript minifying and combining. The option appears when Minify JavaScript or Combine JavaScript is on. See Exclude a page from the cache.
Troubleshooting #
A menu, slider or form stopped working #
- Open the browser console (F12 → Console) and reload the page. Note the file named in the first error.
- Turn off Combine JavaScript, clear all caches and test again.
- If the problem stays, add the script from the error to Excluded JavaScript Files, or turn off Minify JavaScript to confirm the cause.
If Defer or Delay JavaScript is also on, turn those off first to find out which feature causes the problem. More steps are in Broken layout after optimization.
Script changes do not show up #
After you edit a script file directly, use Purge All Cache in the admin bar so the optimized copies are rebuilt, then hard-refresh the page.
For developers #
Useful filters: powered_cache_fo_excluded_js_files, powered_cache_fo_js_do_concat (per script handle) and powered_cache_fo_disable_js_minify. See the hooks reference.