-
Notifications
You must be signed in to change notification settings - Fork 0
JavaScript Optimization
Three independent switches, all off by default. They are separate because their risk profiles are completely different.
| Setting | Risk | What it does |
|---|---|---|
| Minify | Low | Minifies same-origin, non-.min.js files under 2 MB, writes the result to the cache directory, and rewrites the tag |
| Defer | Medium | Adds defer to eligible scripts |
| Delay | High | Holds matching scripts until the first user interaction |
Only files served from your own wp-content are touched. Anything already named .min.js, larger than 2 MB, off-origin, or outside the content directory is left alone. The minified file is named by the SHA-256 of its output, so identical input never regenerates and the URL is safe to cache immutably.
defer preserves execution order but moves execution to after parsing. It breaks scripts that rely on document.write, and inline scripts that expect a library to already be defined. Excluded scripts keep their original loading.
The aggressive one. Matching scripts do not run until the visitor scrolls, moves the pointer, taps, or presses a key. It is very effective on third-party tags and very capable of breaking anything interactive above the fold.
Default delay patterns target analytics and pixels, which is where the win usually is and the risk usually is not:
clarity.ms, connect.facebook.net, google-analytics.com, googletagmanager.com, hotjar.com
These are match patterns compared against scripts your site already loads. GT Performance never contacts these hosts and adds nothing to your site that would.
Add URL fragments under Exceptions, or filter them:
add_filter( 'gt_performance_javascript_exclusions', function ( array $fragments ) {
$fragments[] = '/plugins/my-checkout/';
return $fragments;
} );Analytics and consent plugins are excluded automatically when detected. See Integrations.
- Turn on minify, confirm the site still works.
- Add defer, click through your most interactive templates.
- Only then consider delay, and start with third-party tags rather than your own code.
Test each step on staging. A caching plugin that breaks checkout has cost you more than it saved.
GT Performance · GPL-2.0-or-later · Issues and pull requests welcome
Getting started
Caching
Optimization
Delivery
Operations
Reference