PluginProbe
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN / 1.4.0
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN v1.4.0
1.4.1 1.4.0 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 All 35 releases
← All changes | includes/modules/Minify/MinifyModule.php +71 -23 1.3.4 → 1.4.0 View file →
@@ -18,9 +18,11 @@
18 18 namespace XSpeed\Modules\Minify;
19 19
20 20 defined( 'ABSPATH' ) || exit;
21 21
22 +use XSpeed\Cache;
22 23 use XSpeed\Minifier as LegacyMinifier;
24 +use XSpeed\Minify_Filters;
23 25 use XSpeed\Module;
24 26 use XSpeed\Settings_Manager;
25 27
26 28 final class MinifyModule extends Module {
@@ -33,9 +35,10 @@
33 35 return array(
34 36 'label' => __( 'CSS & JavaScript', 'xspeed' ),
35 37 'tab_label' => __( 'Minify', 'xspeed' ), // its own tab on the CSS & JavaScript page
36 38 'icon' => 'Wand2',
37 - 'description' => __( 'Strip whitespace and rewrite enqueued CSS / JS.', 'xspeed' ),
39 + 'description' => __( 'Makes HTML, CSS and JavaScript files smaller and loads scripts later.', 'xspeed' ),
40 + 'group' => 'performance',
38 41 // Host page: Minify (this module) / Critical CSS (Pro) / Unused
39 42 // CSS (Pro) as tabs — the three CSS/JS optimizations live on one
40 43 // page instead of three sidebar rows (FBS-83633).
41 44 'custom_panel' => 'CssJsPanel',
@@ -51,52 +54,53 @@
51 54 // Names the logged-out caveat up front: minification runs on the
52 55 // request that WRITES a cache entry, and should_cache() refuses
53 56 // logged-in requests — so "view source while logged in" shows
54 57 // un-minified HTML and reads as the feature being broken. (#2)
55 - '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' ),
58 + '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' ),
56 59 ),
57 60 'minify_css' => array(
58 61 'type' => 'bool',
59 62 'default' => false,
60 63 'label' => __( 'Minify CSS', 'xspeed' ),
61 - 'description' => __( 'Compress and rewrite enqueued local stylesheets. External CSS is left untouched.', 'xspeed' ),
64 + 'description' => __( 'Makes your site\'s own CSS files smaller. CSS from other domains is left alone.', 'xspeed' ),
62 65 ),
63 66 'minify_js' => array(
64 67 'type' => 'bool',
65 68 'default' => false,
66 69 'label' => __( 'Minify JavaScript', 'xspeed' ),
67 - 'description' => __( 'Compress enqueued local scripts. Disable if you hit script-loading conflicts on the frontend.', 'xspeed' ),
70 + 'description' => __( 'Makes your site\'s own JavaScript files smaller. Turn off if a script on your site stops working.', 'xspeed' ),
68 71 ),
69 72 'defer_js' => array(
70 73 'type' => 'bool',
71 74 'default' => false,
72 75 'label' => __( 'Defer JavaScript', 'xspeed' ),
73 - 'description' => __( 'Add defer="defer" to enqueued script tags so they execute after HTML parsing. jQuery + its hard dependencies are skipped automatically.', 'xspeed' ),
76 + 'description' => __( 'Runs scripts after the page has loaded, so content shows sooner. jQuery and scripts that need it are skipped.', 'xspeed' ),
74 77 ),
75 78 'delay_js' => array(
76 79 'type' => 'bool',
77 80 'default' => false,
78 - 'label' => __( 'Delay JavaScript Until Interaction', 'xspeed' ),
79 - '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.', 'xspeed' ),
81 + 'label' => __( 'Delay JavaScript', 'xspeed' ),
82 + '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' ),
80 83 ),
81 84 'async_css' => array(
82 85 'type' => 'bool',
83 86 'default' => false,
84 - 'label' => __( 'Load CSS Asynchronously', 'xspeed' ),
85 - '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' ),
87 + 'label' => __( 'Load CSS without blocking', 'xspeed' ),
88 + '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' ),
86 89 ),
87 90 'remove_query_strings' => array(
88 91 'type' => 'bool',
89 92 'default' => false,
90 - 'label' => __( 'Remove Asset Query Strings', 'xspeed' ),
91 - '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' ),
93 + 'label' => __( 'Remove version from file URLs', 'xspeed' ),
94 + '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' ),
95 + 'advanced' => true,
92 96 ),
93 97 'defer_js_excluded' => array(
94 98 'type' => 'list',
95 99 'default' => array( 'jquery-core', 'jquery-migrate' ),
96 100 'item_type' => 'string',
97 - 'label' => __( 'Defer / Delay Exclusions', 'xspeed' ),
98 - 'description' => __( 'Script handles OR URL substrings that skip defer + delay. Defaults exclude jQuery (most themes depend on it being available synchronously). One per line.', 'xspeed' ),
101 + 'label' => __( 'Scripts to never defer or delay', 'xspeed' ),
102 + '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' ),
99 103 // Only relevant once defer OR delay is on — the exclusion list
100 104 // governs both. Uses the `any` (OR) dependency form. (FBS-82227)
101 105 'dependsOn' => array(
102 106 'any' => array(
@@ -108,33 +112,49 @@
108 112 'delay_js_targets' => array(
109 113 'type' => 'list',
110 114 'default' => array(),
111 115 'item_type' => 'string',
112 - 'label' => __( 'Delay Only These Scripts', 'xspeed' ),
113 - '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. One per line.', 'xspeed' ),
116 + 'label' => __( 'Delay only these scripts', 'xspeed' ),
117 + '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' ),
118 + 'info_title' => __( 'Consent banners and Delay JS', 'xspeed' ),
119 + 'info' => sprintf(
120 + /* translators: %s: comma-separated list of consent plugins, each followed by the word to type in parentheses. */
121 + __( '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' ),
122 + implode( ', ', Minify_Filters::consent_manager_labels() )
123 + ),
114 124 'dependsOn' => array( 'field' => 'delay_js' ),
115 125 ),
126 + 'delay_js_smart' => array(
127 + 'type' => 'bool',
128 + 'default' => false,
129 + 'label' => __( 'Smart delay', 'xspeed' ),
130 + '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' ),
131 + 'dependsOn' => array( 'field' => 'delay_js' ),
132 + ),
116 133 'delay_js_timeout' => array(
117 134 'type' => 'int',
118 135 'default' => 8000,
119 136 'min' => 0,
120 137 'max' => 60000,
121 - 'label' => __( 'Delay Failsafe Timeout (ms)', 'xspeed' ),
138 + 'label' => __( 'Delay timeout (ms)', 'xspeed' ),
122 139 'unit' => 'ms',
123 - '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' ),
140 + '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' ),
141 + 'advanced' => true,
124 142 'dependsOn' => array( 'field' => 'delay_js' ),
125 143 ),
126 144 'combine_css' => array(
127 145 'type' => 'bool',
128 146 'default' => false,
129 - 'label' => __( 'Combine CSS Files', 'xspeed' ),
130 - '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' ),
147 + 'label' => __( 'Combine CSS files', 'xspeed' ),
148 + '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' ),
149 + 'advanced' => true,
131 150 ),
132 151 'combine_js' => array(
133 152 'type' => 'bool',
134 153 'default' => false,
135 - 'label' => __( 'Combine JavaScript Files', 'xspeed' ),
136 - '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' ),
154 + 'label' => __( 'Combine JavaScript files', 'xspeed' ),
155 + 'description' => __( 'Joins your site\'s own scripts into one file. Turn off if a script stops working after you enable it.', 'xspeed' ),
156 + 'advanced' => true,
137 157 ),
138 158 );
139 159 }
140 160
@@ -329,14 +349,42 @@
329 349 return;
330 350 }
331 351
332 352 if ( 'purge' === $action ) {
333 - LegacyMinifier::purge_minified();
334 - \WP_CLI::success( 'Minify cache purged.' );
353 + // Deleting the files alone left every cached page linking names
354 + // that were gone. The assets purge takes the pages with it and
355 + // tells the edge. On a network, a bare `wp xspeed minify purge`
356 + // is a network purge (min/ is shared by every blog); with --url
357 + // it is that site's assets purge.
358 + $network = is_multisite() && ! self::cli_url_given();
359 + $count = $network
360 + ? Cache::purge_assets( 'cli', true )
361 + : Cache::purge_type( 'assets', 'cli' );
362 + \WP_CLI::success(
363 + sprintf(
364 + 'Minify cache purged; %d cached page(s) removed%s.',
365 + $count,
366 + $network ? ' across the network' : ''
367 + )
368 + );
335 369 return;
336 370 }
337 371
338 372 \WP_CLI::error( "Unknown action: $action" );
373 + }
374 +
375 + /**
376 + * Whether this command was pointed at one site with --url.
377 + *
378 + * Only a real WP-CLI run has global config to read. The MCP bridge runs
379 + * the command inside a request for one site, which is the same thing as
380 + * --url, so anything without WP-CLI's config reads as site-scoped.
381 + */
382 + private static function cli_url_given(): bool {
383 + if ( ! class_exists( '\\WP_CLI' ) || ! method_exists( '\\WP_CLI', 'get_config' ) ) {
384 + return true;
385 + }
386 + return '' !== (string) \WP_CLI::get_config( 'url' );
339 387 }
340 388
341 389 /**
342 390 * Minify has no master switch -- it is on when any of minify_html /