PluginProbe
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN / 1.3.7
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN v1.3.7
1.3.7 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 All 33 releases
← All changes | includes/modules/Minify/MinifyModule.php +116 -27 1.1.3 → 1.3.7 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,13 @@
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' => __( 'Makes HTML, CSS and JavaScript files smaller and loads scripts later.', 'xspeed' ),
39 + 'group' => 'performance',
38 40 // Host page: Minify (this module) / Critical CSS (Pro) / Unused
39 41 // CSS (Pro) as tabs — the three CSS/JS optimizations live on one
40 42 // page instead of three sidebar rows (FBS-83633).
41 43 'custom_panel' => 'CssJsPanel',
@@ -46,53 +48,58 @@
46 48 return array(
47 49 'minify_html' => array(
48 50 'type' => 'bool',
49 51 'default' => false,
50 - 'label' => 'Minify HTML',
51 - 'description' => 'Strip whitespace and comments from HTML output. Safe on most themes.',
52 + 'label' => __( 'Minify HTML', 'xspeed' ),
53 + // Names the logged-out caveat up front: minification runs on the
54 + // request that WRITES a cache entry, and should_cache() refuses
55 + // logged-in requests — so "view source while logged in" shows
56 + // un-minified HTML and reads as the feature being broken. (#2)
57 + 'description' => __( 'Removes spaces and comments from your pages. Safe on most themes. Only logged-out visitors see it, so check in a private window.', 'xspeed' ),
52 58 ),
53 59 'minify_css' => array(
54 60 'type' => 'bool',
55 61 'default' => false,
56 - 'label' => 'Minify CSS',
57 - 'description' => 'Compress and rewrite enqueued local stylesheets. External CSS is left untouched.',
62 + 'label' => __( 'Minify CSS', 'xspeed' ),
63 + 'description' => __( 'Makes your site\'s own CSS files smaller. CSS from other domains is left alone.', 'xspeed' ),
58 64 ),
59 65 'minify_js' => array(
60 66 'type' => 'bool',
61 67 'default' => false,
62 - 'label' => 'Minify JavaScript',
63 - 'description' => 'Compress enqueued local scripts. Disable if you hit script-loading conflicts on the frontend.',
68 + 'label' => __( 'Minify JavaScript', 'xspeed' ),
69 + 'description' => __( 'Makes your site\'s own JavaScript files smaller. Turn off if a script on your site stops working.', 'xspeed' ),
64 70 ),
65 71 'defer_js' => array(
66 72 'type' => 'bool',
67 73 '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.',
74 + 'label' => __( 'Defer JavaScript', 'xspeed' ),
75 + 'description' => __( 'Runs scripts after the page has loaded, so content shows sooner. jQuery and scripts that need it are skipped.', 'xspeed' ),
70 76 ),
71 77 'delay_js' => array(
72 78 'type' => 'bool',
73 79 '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.',
80 + 'label' => __( 'Delay JavaScript', 'xspeed' ),
81 + 'description' => __( 'Scripts load only when the visitor scrolls, taps or types. Pages show much sooner, but test menus and sliders. Cookie consent banners still load first.', 'xspeed' ),
76 82 ),
77 83 'async_css' => array(
78 84 'type' => 'bool',
79 85 '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.',
86 + 'label' => __( 'Load CSS without blocking', 'xspeed' ),
87 + 'description' => __( 'On pages that have critical CSS, the page shows before the rest of its CSS finishes loading. Pages without critical CSS keep loading their CSS normally, because deferring it makes the page show unstyled and then jump.', 'xspeed' ),
82 88 ),
83 89 'remove_query_strings' => array(
84 90 'type' => 'bool',
85 91 '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.',
92 + 'label' => __( 'Remove version from file URLs', 'xspeed' ),
93 + 'description' => __( 'Removes ?ver= from CSS and JS links, which some CDNs cache better. After a plugin update, returning visitors may keep old files until their browser cache expires.', 'xspeed' ),
94 + 'advanced' => true,
88 95 ),
89 96 'defer_js_excluded' => array(
90 97 'type' => 'list',
91 98 'default' => array( 'jquery-core', 'jquery-migrate' ),
92 99 '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.',
100 + 'label' => __( 'Scripts to never defer or delay', 'xspeed' ),
101 + 'description' => __( 'Script handles or parts of script URLs, one per line. jQuery is listed because most themes need it early; cookie consent banners are skipped on their own.', 'xspeed' ),
95 102 // Only relevant once defer OR delay is on — the exclusion list
96 103 // governs both. Uses the `any` (OR) dependency form. (FBS-82227)
97 104 'dependsOn' => array(
98 105 'any' => array(
@@ -104,32 +111,49 @@
104 111 'delay_js_targets' => array(
105 112 'type' => 'list',
106 113 'default' => array(),
107 114 'item_type' => 'string',
108 - 'label' => 'Delay Only These Scripts',
109 - 'description' => 'Script handles OR URL substrings. When non-empty, ONLY matching scripts are delayed — everything else loads normally. Leave empty to delay all scripts (minus the exclusions above). Ideal for postponing one heavy third-party embed without touching the rest of the page. 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. One per line.',
115 + 'label' => __( 'Delay only these scripts', 'xspeed' ),
116 + 'description' => __( 'Script handles or parts of script URLs, one per line. Leave empty to delay all scripts; otherwise only these, plus known trackers and chat widgets, are delayed.', 'xspeed' ),
117 + 'info_title' => __( 'Consent banners and Delay JS', 'xspeed' ),
118 + 'info' => sprintf(
119 + /* translators: %s: comma-separated list of consent plugins, each followed by the word to type in parentheses. */
120 + __( '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 Scripts to never defer or delay always wins.', 'xspeed' ),
121 + implode( ', ', Minify_Filters::consent_manager_labels() )
122 + ),
110 123 'dependsOn' => array( 'field' => 'delay_js' ),
111 124 ),
125 + 'delay_js_smart' => array(
126 + 'type' => 'bool',
127 + 'default' => false,
128 + 'label' => __( 'Smart delay', 'xspeed' ),
129 + 'description' => __( 'Also delays scripts that code on the page depends on, which helps page builder sites most. The riskiest setting here, so test menus and sliders.', 'xspeed' ),
130 + 'dependsOn' => array( 'field' => 'delay_js' ),
131 + ),
112 132 'delay_js_timeout' => array(
113 133 'type' => 'int',
114 134 'default' => 8000,
115 135 'min' => 0,
116 136 'max' => 60000,
117 - 'label' => 'Delay Failsafe Timeout (ms)',
118 - '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.',
137 + 'label' => __( 'Delay timeout (ms)', 'xspeed' ),
138 + 'unit' => 'ms',
139 + 'description' => __( 'Load delayed scripts after this long if the visitor does nothing. Set 0 to wait for a scroll, tap or key press only.', 'xspeed' ),
140 + 'advanced' => true,
119 141 'dependsOn' => array( 'field' => 'delay_js' ),
120 142 ),
121 143 'combine_css' => array(
122 144 'type' => 'bool',
123 145 'default' => false,
124 - 'label' => 'Combine CSS Files',
125 - '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.',
146 + 'label' => __( 'Combine CSS files', 'xspeed' ),
147 + 'description' => __( 'Joins your site\'s own CSS files into one. This helps only on old HTTP/1.1 servers, so leave it off on most hosts.', 'xspeed' ),
148 + 'advanced' => true,
126 149 ),
127 150 'combine_js' => array(
128 151 'type' => 'bool',
129 152 'default' => false,
130 - 'label' => 'Combine JavaScript Files',
131 - '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.',
153 + 'label' => __( 'Combine JavaScript files', 'xspeed' ),
154 + 'description' => __( 'Joins your site\'s own scripts into one file. Turn off if a script stops working after you enable it.', 'xspeed' ),
155 + 'advanced' => true,
132 156 ),
133 157 );
134 158 }
135 159
@@ -189,8 +213,9 @@
189 213 array(
190 214 'name' => 'xspeed minify',
191 215 'callback' => array( $this, 'cli_handler' ),
192 216 'shortdesc' => 'Inspect or purge xSpeed minify cache.',
217 + '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.',
193 218 'synopsis' => array(
194 219 array(
195 220 'type' => 'positional',
196 221 'name' => 'action',
@@ -210,8 +235,26 @@
210 235 * 2. Instantiate the v1 Minifier engine; it now reads from
211 236 * Settings_Manager::get('minify') via its updated read path.
212 237 */
213 238 public function boot(): void {
239 + /*
240 + * Deferred to `init`: both calls below read this module's settings,
241 + * which builds settings_schema(), whose labels go through __().
242 + * boot() runs on `plugins_loaded`, before `after_setup_theme` — the
243 + * earliest point WordPress 6.7+ considers safe to translate — so doing
244 + * it here fires _load_textdomain_just_in_time on every request and
245 + * resolves those labels against an unloaded domain.
246 + *
247 + * Every filter LegacyMinifier registers fires after `init`, so running
248 + * one hook later is equivalent.
249 + */
250 + add_action( 'init', array( $this, 'boot_on_init' ) );
251 + }
252 +
253 + /**
254 + * The real boot body — see boot() for why it runs on `init`.
255 + */
256 + public function boot_on_init(): void {
214 257 $this->seed_from_legacy_if_needed();
215 258 new LegacyMinifier();
216 259 }
217 260
@@ -220,8 +263,45 @@
220 263 // run more than once.
221 264 $this->seed_from_legacy_if_needed();
222 265 }
223 266
267 + /**
268 + * Say so when HTML minification is switched on but suppressed.
269 + *
270 + * `Minifier::skip_reason()` was consulted only by `wp xspeed minify status`
271 + * — the dashboard read "on" while `minify_html()` returned its input
272 + * untouched, so the feature looked broken rather than paused. A field
273 + * report showed a live site with `minify_html: on` and 3,856 indented lines
274 + * delivered, and nothing anywhere explaining the contradiction. (#2)
275 + *
276 + * @return array<int,array<string,mixed>>
277 + */
278 + public function ui_notices(): array {
279 + $opts = $this->get_settings();
280 + if ( empty( $opts['minify_html'] ) ) {
281 + return array();
282 + }
283 +
284 + $reason = LegacyMinifier::skip_reason();
285 + if ( '' === $reason ) {
286 + return array();
287 + }
288 +
289 + // Two different causes, two different fixes — naming the wrong one
290 + // sends the user hunting in the wrong file.
291 + $body = 'wp_debug' === $reason
292 + ? __( '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' )
293 + : __( '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' );
294 +
295 + return array(
296 + array(
297 + 'tone' => 'info',
298 + 'title' => __( 'HTML minification is on but currently paused', 'xspeed' ),
299 + 'body' => $body,
300 + ),
301 + );
302 + }
303 +
224 304 private function seed_from_legacy_if_needed(): void {
225 305 $existing = get_option( 'xspeed_module_minify', null );
226 306 if ( null !== $existing ) {
227 307 return;
@@ -274,6 +354,15 @@
274 354 return;
275 355 }
276 356
277 357 \WP_CLI::error( "Unknown action: $action" );
358 + }
359 +
360 + /**
361 + * Minify has no master switch -- it is on when any of minify_html /
362 + * minify_css / minify_js / defer_js / delay_js / async_css /
363 + * remove_query_strings is set. (#363)
364 + */
365 + public function is_active(): ?bool {
366 + return $this->any_bool_flag_on();
278 367 }
279 368 }