PluginProbe
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN / 1.3.6
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN v1.3.6
1.3.6 1.3.5 1.3.4 1.3.3 1.3.2 1.3.1 1.3.0 1.2.4 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 All 32 releases
← All changes | includes/modules/Minify/MinifyModule.php +137 -24 1.1.0 → 1.3.6 View file →
@@ -19,8 +19,9 @@
19 19
20 20 defined( 'ABSPATH' ) || exit;
21 21
22 22 use XSpeed\Minifier as LegacyMinifier;
23 +use XSpeed\Minify_Filters;
23 24 use XSpeed\Module;
24 25 use XSpeed\Settings_Manager;
25 26
26 27 final class MinifyModule extends Module {
@@ -30,12 +31,12 @@
30 31 public const VERSION = '1.2.0';
31 32
32 33 public function ui_metadata(): array {
33 34 return array(
34 - 'label' => 'CSS & JavaScript',
35 - 'tab_label' => 'Minify', // its own tab on the CSS & JavaScript page
35 + 'label' => __( 'CSS & JavaScript', 'xspeed' ),
36 + 'tab_label' => __( 'Minify', 'xspeed' ), // its own tab on the CSS & JavaScript page
36 37 'icon' => 'Wand2',
37 - 'description' => 'Strip whitespace and rewrite enqueued CSS / JS.',
38 + 'description' => __( 'Strip whitespace and rewrite enqueued CSS / JS.', 'xspeed' ),
38 39 // Host page: Minify (this module) / Critical CSS (Pro) / Unused
39 40 // CSS (Pro) as tabs — the three CSS/JS optimizations live on one
40 41 // page instead of three sidebar rows (FBS-83633).
41 42 'custom_panel' => 'CssJsPanel',
@@ -46,53 +47,57 @@
46 47 return array(
47 48 'minify_html' => array(
48 49 'type' => 'bool',
49 50 'default' => false,
50 - 'label' => 'Minify HTML',
51 - 'description' => 'Strip whitespace and comments from HTML output. Safe on most themes.',
51 + 'label' => __( 'Minify HTML', 'xspeed' ),
52 + // Names the logged-out caveat up front: minification runs on the
53 + // request that WRITES a cache entry, and should_cache() refuses
54 + // logged-in requests — so "view source while logged in" shows
55 + // un-minified HTML and reads as the feature being broken. (#2)
56 + 'description' => __( 'Strip whitespace and comments from HTML output, including inline <style> and <script> blocks. Safe on most themes. Applies to cached (logged-out) responses — view the page in a private window to see the result.', 'xspeed' ),
52 57 ),
53 58 'minify_css' => array(
54 59 'type' => 'bool',
55 60 'default' => false,
56 - 'label' => 'Minify CSS',
57 - 'description' => 'Compress and rewrite enqueued local stylesheets. External CSS is left untouched.',
61 + 'label' => __( 'Minify CSS', 'xspeed' ),
62 + 'description' => __( 'Compress and rewrite enqueued local stylesheets. External CSS is left untouched.', 'xspeed' ),
58 63 ),
59 64 'minify_js' => array(
60 65 'type' => 'bool',
61 66 'default' => false,
62 - 'label' => 'Minify JavaScript',
63 - 'description' => 'Compress enqueued local scripts. Disable if you hit script-loading conflicts on the frontend.',
67 + 'label' => __( 'Minify JavaScript', 'xspeed' ),
68 + 'description' => __( 'Compress enqueued local scripts. Disable if you hit script-loading conflicts on the frontend.', 'xspeed' ),
64 69 ),
65 70 'defer_js' => array(
66 71 'type' => 'bool',
67 72 'default' => false,
68 - 'label' => 'Defer JavaScript',
69 - 'description' => 'Add defer="defer" to enqueued script tags so they execute after HTML parsing. jQuery + its hard dependencies are skipped automatically.',
73 + 'label' => __( 'Defer JavaScript', 'xspeed' ),
74 + 'description' => __( 'Add defer="defer" to enqueued script tags so they execute after HTML parsing. jQuery + its hard dependencies are skipped automatically.', 'xspeed' ),
70 75 ),
71 76 'delay_js' => array(
72 77 'type' => 'bool',
73 78 'default' => false,
74 - 'label' => 'Delay JavaScript Until Interaction',
75 - 'description' => 'Postpone script loading until the visitor scrolls, moves the mouse, taps, or presses a key. Drastically improves first paint on script-heavy pages; can break above-the-fold scripted UI — test before leaving on.',
79 + 'label' => __( 'Delay JavaScript Until Interaction', 'xspeed' ),
80 + 'description' => __( 'Postpone script loading until the visitor scrolls, moves the mouse, taps, or presses a key. Drastically improves first paint on script-heavy pages; can break above-the-fold scripted UI — test before leaving on. Cookie-consent banners (CookieYes, Complianz, Cookiebot, NotificationX, Cookie Notice, Borlabs, Real Cookie Banner and others) are not delayed, so the visitor is still asked before anything else runs. To delay one on purpose, name it in Delay Only These Scripts.', 'xspeed' ),
76 81 ),
77 82 'async_css' => array(
78 83 'type' => 'bool',
79 84 'default' => false,
80 - 'label' => 'Load CSS Asynchronously',
81 - 'description' => 'Rewrite stylesheet link tags to load non-blocking via the print-then-all pattern. Pairs well with critical-CSS workflows; can cause a flash of unstyled content if the theme has no critical CSS.',
85 + 'label' => __( 'Load CSS Asynchronously', 'xspeed' ),
86 + 'description' => __( 'Rewrite stylesheet link tags to load non-blocking via the print-then-all pattern. Pairs well with critical-CSS workflows; can cause a flash of unstyled content if the theme has no critical CSS.', 'xspeed' ),
82 87 ),
83 88 'remove_query_strings' => array(
84 89 'type' => 'bool',
85 90 'default' => false,
86 - 'label' => 'Remove Asset Query Strings',
87 - 'description' => 'Strip ?ver=X.Y from enqueued CSS / JS URLs. Some CDN caches and proxies cache better when query strings are absent.',
91 + 'label' => __( 'Remove Asset Query Strings', 'xspeed' ),
92 + 'description' => __( 'Strip ?ver=X.Y from enqueued CSS / JS URLs. Some CDN caches and proxies cache better when query strings are absent. Files under wp-content/uploads keep their version — page builders and consent plugins rewrite generated CSS there in place, and ?ver is what tells browsers to refetch it. Plugin, theme and core assets are still stripped: with Browser Cache on, an update reaches returning visitors only when their browser cache expires.', 'xspeed' ),
88 93 ),
89 94 'defer_js_excluded' => array(
90 95 'type' => 'list',
91 96 'default' => array( 'jquery-core', 'jquery-migrate' ),
92 97 'item_type' => 'string',
93 - 'label' => 'Defer / Delay Exclusions',
94 - 'description' => 'Script handles OR URL substrings that skip defer + delay. Defaults exclude jQuery (most themes depend on it being available synchronously). One per line.',
98 + 'label' => __( 'Defer / Delay Exclusions', 'xspeed' ),
99 + 'description' => __( 'Script handles OR URL substrings that skip defer + delay. Defaults exclude jQuery (most themes depend on it being available synchronously). Cookie-consent banners are skipped without being listed here. An entry here also wins over the same script in Delay Only These Scripts. One per line.', 'xspeed' ),
95 100 // Only relevant once defer OR delay is on — the exclusion list
96 101 // governs both. Uses the `any` (OR) dependency form. (FBS-82227)
97 102 'dependsOn' => array(
98 103 'any' => array(
@@ -100,19 +105,50 @@
100 105 array( 'field' => 'delay_js' ),
101 106 ),
102 107 ),
103 108 ),
109 + 'delay_js_targets' => array(
110 + 'type' => 'list',
111 + 'default' => array(),
112 + 'item_type' => 'string',
113 + 'label' => __( 'Delay Only These Scripts', 'xspeed' ),
114 + 'description' => __( 'Script handles OR URL substrings. When non-empty, matching scripts are delayed, plus the known third-party tags xSpeed recognises on its own (analytics, tag managers, chat widgets, review embeds, error trackers) — so a heavy vendor script is postponed even when it is not listed here. Leave empty to delay all scripts (minus the exclusions above). Handles are the more reliable selector — a URL substring has to match the script\'s original URL, and minification rewrites that to a hashed cache path. Cookie-consent banners are only delayed when an entry names one, for example notificationx or cookiebot. A broad entry such as /plugins/ does not delay them. One per line.', 'xspeed' ),
115 + 'info_title' => __( 'Consent banners and Delay JS', 'xspeed' ),
116 + 'info' => sprintf(
117 + /* translators: %s: comma-separated list of consent plugins, each followed by the word to type in parentheses. */
118 + __( 'These consent banners load straight away, even with Delay JS on: %s. To delay one on purpose, add the word in parentheses, or the script handle, to this list. An entry that only matches part of the address, such as /plugins/ or .js, never delays a banner, and an entry in Defer / Delay Exclusions always wins.', 'xspeed' ),
119 + implode( ', ', Minify_Filters::consent_manager_labels() )
120 + ),
121 + 'dependsOn' => array( 'field' => 'delay_js' ),
122 + ),
123 + 'delay_js_smart' => array(
124 + 'type' => 'bool',
125 + 'default' => false,
126 + 'label' => __( 'Smart Delay (Carry Inline Snippets)', 'xspeed' ),
127 + 'description' => __( 'Normally a script is left running at load when inline code on the page depends on it — on builder pages that keeps most scripts eager even with Delay JavaScript on. Smart Delay postpones those scripts anyway and parks their inline snippets with them; everything replays in page order on the first interaction. The most aggressive setting on this page: test menus, sliders, and toggles before leaving it on. Exclusions above still win, and consent banners still run first.', 'xspeed' ),
128 + 'dependsOn' => array( 'field' => 'delay_js' ),
129 + ),
130 + 'delay_js_timeout' => array(
131 + 'type' => 'int',
132 + 'default' => 8000,
133 + 'min' => 0,
134 + 'max' => 60000,
135 + 'label' => __( 'Delay Failsafe Timeout (ms)', 'xspeed' ),
136 + 'unit' => 'ms',
137 + 'description' => __( 'Load delayed scripts automatically after this many milliseconds when the visitor never interacts. Set to 0 for interaction-only, with no timer: a timer that fires inside a lab tool\'s measurement window loads the "delayed" scripts anyway and inflates the reported TTI. Keep a non-zero value if a delayed script must eventually run for visitors who never scroll, tap, or type.', 'xspeed' ),
138 + 'dependsOn' => array( 'field' => 'delay_js' ),
139 + ),
104 140 'combine_css' => array(
105 141 'type' => 'bool',
106 142 'default' => false,
107 - 'label' => 'Combine CSS Files',
108 - 'description' => 'Concatenate enqueued local stylesheets into a single file (with @import and url(…) paths resolved). External CSS is left alone. Pairs poorly with HTTP/2 push — only enable on HTTP/1.1 hosts.',
143 + 'label' => __( 'Combine CSS Files', 'xspeed' ),
144 + 'description' => __( 'Concatenate enqueued local stylesheets into a single file (with @import and url(…) paths resolved). External CSS is left alone. Pairs poorly with HTTP/2 push — only enable on HTTP/1.1 hosts.', 'xspeed' ),
109 145 ),
110 146 'combine_js' => array(
111 147 'type' => 'bool',
112 148 'default' => false,
113 - 'label' => 'Combine JavaScript Files',
114 - 'description' => 'Concatenate enqueued local scripts into a single file. External scripts + scripts marked async / deferred are left alone. Disable if you hit dependency-order issues; the combiner respects WordPress enqueue order but inline scripts attached via wp_add_inline_script can shift behavior.',
149 + 'label' => __( 'Combine JavaScript Files', 'xspeed' ),
150 + 'description' => __( 'Concatenate enqueued local scripts into a single file. External scripts + scripts marked async / deferred are left alone. Disable if you hit dependency-order issues; the combiner respects WordPress enqueue order but inline scripts attached via wp_add_inline_script can shift behavior.', 'xspeed' ),
115 151 ),
116 152 );
117 153 }
118 154
@@ -172,8 +208,9 @@
172 208 array(
173 209 'name' => 'xspeed minify',
174 210 'callback' => array( $this, 'cli_handler' ),
175 211 'shortdesc' => 'Inspect or purge xSpeed minify cache.',
212 + 'ai_hint' => 'Which CSS/JS optimizations are active (minify, combine, defer, delay, async)? Use for questions about render-blocking resources, unminified assets in PageSpeed, or when JavaScript broke after enabling optimizations.',
176 213 'synopsis' => array(
177 214 array(
178 215 'type' => 'positional',
179 216 'name' => 'action',
@@ -193,8 +230,26 @@
193 230 * 2. Instantiate the v1 Minifier engine; it now reads from
194 231 * Settings_Manager::get('minify') via its updated read path.
195 232 */
196 233 public function boot(): void {
234 + /*
235 + * Deferred to `init`: both calls below read this module's settings,
236 + * which builds settings_schema(), whose labels go through __().
237 + * boot() runs on `plugins_loaded`, before `after_setup_theme` — the
238 + * earliest point WordPress 6.7+ considers safe to translate — so doing
239 + * it here fires _load_textdomain_just_in_time on every request and
240 + * resolves those labels against an unloaded domain.
241 + *
242 + * Every filter LegacyMinifier registers fires after `init`, so running
243 + * one hook later is equivalent.
244 + */
245 + add_action( 'init', array( $this, 'boot_on_init' ) );
246 + }
247 +
248 + /**
249 + * The real boot body — see boot() for why it runs on `init`.
250 + */
251 + public function boot_on_init(): void {
197 252 $this->seed_from_legacy_if_needed();
198 253 new LegacyMinifier();
199 254 }
200 255
@@ -203,8 +258,45 @@
203 258 // run more than once.
204 259 $this->seed_from_legacy_if_needed();
205 260 }
206 261
262 + /**
263 + * Say so when HTML minification is switched on but suppressed.
264 + *
265 + * `Minifier::skip_reason()` was consulted only by `wp xspeed minify status`
266 + * — the dashboard read "on" while `minify_html()` returned its input
267 + * untouched, so the feature looked broken rather than paused. A field
268 + * report showed a live site with `minify_html: on` and 3,856 indented lines
269 + * delivered, and nothing anywhere explaining the contradiction. (#2)
270 + *
271 + * @return array<int,array<string,mixed>>
272 + */
273 + public function ui_notices(): array {
274 + $opts = $this->get_settings();
275 + if ( empty( $opts['minify_html'] ) ) {
276 + return array();
277 + }
278 +
279 + $reason = LegacyMinifier::skip_reason();
280 + if ( '' === $reason ) {
281 + return array();
282 + }
283 +
284 + // Two different causes, two different fixes — naming the wrong one
285 + // sends the user hunting in the wrong file.
286 + $body = 'wp_debug' === $reason
287 + ? __( 'HTML minification is paused because WP_DEBUG is enabled in wp-config.php. Readable HTML is usually what you want while debugging, so xSpeed leaves the markup alone. Cached pages are served un-minified until WP_DEBUG is turned off.', 'xspeed' )
288 + : __( 'HTML minification is paused because a plugin or theme is returning true from the xspeed_skip_minify filter. Cached pages are served un-minified until that filter stops suppressing it.', 'xspeed' );
289 +
290 + return array(
291 + array(
292 + 'tone' => 'info',
293 + 'title' => __( 'HTML minification is on but currently paused', 'xspeed' ),
294 + 'body' => $body,
295 + ),
296 + );
297 + }
298 +
207 299 private function seed_from_legacy_if_needed(): void {
208 300 $existing = get_option( 'xspeed_module_minify', null );
209 301 if ( null !== $existing ) {
210 302 return;
@@ -232,9 +324,21 @@
232 324 $action = $args[0] ?? 'status';
233 325
234 326 if ( 'status' === $action ) {
235 327 $opts = Settings_Manager::get( self::SLUG );
236 - \WP_CLI::log( sprintf( 'minify_html: %s', $opts['minify_html'] ? 'on' : 'off' ) );
328 + // A bare "on" is a lie when the skip guard is active: the
329 + // setting is stored, but Minifier::minify_html() returns its
330 + // input untouched and the delivered HTML is unchanged. Say so
331 + // on the same line, so the contradiction can never be read as
332 + // "minify is broken".
333 + $skip = \XSpeed\Minifier::skip_reason();
334 + $html_state = $opts['minify_html'] ? 'on' : 'off';
335 + if ( $opts['minify_html'] && '' !== $skip ) {
336 + $html_state .= ( 'wp_debug' === $skip )
337 + ? ' (NOT APPLIED — WP_DEBUG is enabled; set WP_DEBUG to false to minify HTML)'
338 + : ' (NOT APPLIED — suppressed by the xspeed_skip_minify filter)';
339 + }
340 + \WP_CLI::log( sprintf( 'minify_html: %s', $html_state ) );
237 341 \WP_CLI::log( sprintf( 'minify_css : %s', $opts['minify_css'] ? 'on' : 'off' ) );
238 342 \WP_CLI::log( sprintf( 'minify_js : %s', $opts['minify_js'] ? 'on' : 'off' ) );
239 343 return;
240 344 }
@@ -245,6 +349,15 @@
245 349 return;
246 350 }
247 351
248 352 \WP_CLI::error( "Unknown action: $action" );
353 + }
354 +
355 + /**
356 + * Minify has no master switch -- it is on when any of minify_html /
357 + * minify_css / minify_js / defer_js / delay_js / async_css /
358 + * remove_query_strings is set. (#363)
359 + */
360 + public function is_active(): ?bool {
361 + return $this->any_bool_flag_on();
249 362 }
250 363 }