| @@ -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 { |
| @@ -33,9 +34,10 @@ | ||
| 33 | 34 | return array( |
| 34 | 35 | 'label' => __( 'CSS & JavaScript', 'xspeed' ), |
| 35 | 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.', 'xspeed' ), | |
| 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', |
| @@ -51,52 +53,53 @@ | ||
| 51 | 53 | // Names the logged-out caveat up front: minification runs on the |
| 52 | 54 | // request that WRITES a cache entry, and should_cache() refuses |
| 53 | 55 | // logged-in requests — so "view source while logged in" shows |
| 54 | 56 | // 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' ), | |
| 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' ), | |
| 56 | 58 | ), |
| 57 | 59 | 'minify_css' => array( |
| 58 | 60 | 'type' => 'bool', |
| 59 | 61 | 'default' => false, |
| 60 | 62 | 'label' => __( 'Minify CSS', 'xspeed' ), |
| 61 | - 'description' => __( 'Compress and rewrite enqueued local stylesheets. External CSS is left untouched.', 'xspeed' ), | |
| 63 | + 'description' => __( 'Makes your site\'s own CSS files smaller. CSS from other domains is left alone.', 'xspeed' ), | |
| 62 | 64 | ), |
| 63 | 65 | 'minify_js' => array( |
| 64 | 66 | 'type' => 'bool', |
| 65 | 67 | 'default' => false, |
| 66 | 68 | 'label' => __( 'Minify JavaScript', 'xspeed' ), |
| 67 | - 'description' => __( 'Compress enqueued local scripts. Disable if you hit script-loading conflicts on the frontend.', 'xspeed' ), | |
| 69 | + 'description' => __( 'Makes your site\'s own JavaScript files smaller. Turn off if a script on your site stops working.', 'xspeed' ), | |
| 68 | 70 | ), |
| 69 | 71 | 'defer_js' => array( |
| 70 | 72 | 'type' => 'bool', |
| 71 | 73 | 'default' => false, |
| 72 | 74 | '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' ), | |
| 75 | + 'description' => __( 'Runs scripts after the page has loaded, so content shows sooner. jQuery and scripts that need it are skipped.', 'xspeed' ), | |
| 74 | 76 | ), |
| 75 | 77 | 'delay_js' => array( |
| 76 | 78 | 'type' => 'bool', |
| 77 | 79 | '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' ), | |
| 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' ), | |
| 80 | 82 | ), |
| 81 | 83 | 'async_css' => array( |
| 82 | 84 | 'type' => 'bool', |
| 83 | 85 | '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' ), | |
| 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' ), | |
| 86 | 88 | ), |
| 87 | 89 | 'remove_query_strings' => array( |
| 88 | 90 | 'type' => 'bool', |
| 89 | 91 | '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' ), | |
| 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, | |
| 92 | 95 | ), |
| 93 | 96 | 'defer_js_excluded' => array( |
| 94 | 97 | 'type' => 'list', |
| 95 | 98 | 'default' => array( 'jquery-core', 'jquery-migrate' ), |
| 96 | 99 | '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' ), | |
| 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' ), | |
| 99 | 102 | // Only relevant once defer OR delay is on — the exclusion list |
| 100 | 103 | // governs both. Uses the `any` (OR) dependency form. (FBS-82227) |
| 101 | 104 | 'dependsOn' => array( |
| 102 | 105 | 'any' => array( |
| @@ -108,33 +111,49 @@ | ||
| 108 | 111 | 'delay_js_targets' => array( |
| 109 | 112 | 'type' => 'list', |
| 110 | 113 | 'default' => array(), |
| 111 | 114 | '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' ), | |
| 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 | + ), | |
| 114 | 123 | 'dependsOn' => array( 'field' => 'delay_js' ), |
| 115 | 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 | + ), | |
| 116 | 132 | 'delay_js_timeout' => array( |
| 117 | 133 | 'type' => 'int', |
| 118 | 134 | 'default' => 8000, |
| 119 | 135 | 'min' => 0, |
| 120 | 136 | 'max' => 60000, |
| 121 | - 'label' => __( 'Delay Failsafe Timeout (ms)', 'xspeed' ), | |
| 137 | + 'label' => __( 'Delay timeout (ms)', 'xspeed' ), | |
| 122 | 138 | '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' ), | |
| 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, | |
| 124 | 141 | 'dependsOn' => array( 'field' => 'delay_js' ), |
| 125 | 142 | ), |
| 126 | 143 | 'combine_css' => array( |
| 127 | 144 | 'type' => 'bool', |
| 128 | 145 | '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' ), | |
| 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, | |
| 131 | 149 | ), |
| 132 | 150 | 'combine_js' => array( |
| 133 | 151 | 'type' => 'bool', |
| 134 | 152 | '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' ), | |
| 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, | |
| 137 | 156 | ), |
| 138 | 157 | ); |
| 139 | 158 | } |
| 140 | 159 | |