PluginProbe
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN / 1.3.2
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN v1.3.2
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 1.1.6 1.1.7 1.1.8 1.2.0 All 28 releases
← All changes | includes/modules/BrowserCache/BrowserCacheModule.php +44 -22 1.0.71.3.2 View file →
@@ -16,8 +16,9 @@
16 16
17 17 defined( 'ABSPATH' ) || exit;
18 18
19 19 use XSpeed\Browser_Cache;
20 +use XSpeed\Deep_Link;
20 21 use XSpeed\Module;
21 22 use XSpeed\Server;
22 23
23 24 final class BrowserCacheModule extends Module {
@@ -27,11 +28,11 @@
27 28 public const VERSION = '1.0.0';
28 29
29 30 public function ui_metadata(): array {
30 31 return array(
31 - 'label' => 'Browser Cache',
32 + 'label' => __( 'Browser Cache', 'xspeed' ),
32 33 'icon' => 'Clock',
33 - 'description' => 'Tell browsers (and intermediate CDNs) how long to cache static assets and HTML.',
34 + 'description' => __( 'Tell browsers (and intermediate CDNs) how long to cache static assets and HTML.', 'xspeed' ),
34 35 );
35 36 }
36 37
37 38 public function settings_schema(): array {
@@ -38,10 +39,10 @@
38 39 return array(
39 40 'enabled' => array(
40 41 'type' => 'bool',
41 42 'default' => false,
42 - 'label' => 'Enable browser cache headers',
43 - 'description' => 'On Apache/LiteSpeed this writes Cache-Control + Expires rules into .htaccess. On nginx it just stores the settings — you paste the snippet into your server block manually.',
43 + 'label' => __( 'Enable browser cache headers', 'xspeed' ),
44 + 'description' => __( 'On Apache/LiteSpeed this writes Cache-Control + Expires rules into .htaccess. On nginx it just stores the settings — you paste the snippet into your server block manually.', 'xspeed' ),
44 45 ),
45 46 'asset_ttl' => array(
46 47 'type' => 'int',
47 48 'default' => Browser_Cache::DEFAULT_ASSET_TTL,
@@ -46,10 +47,11 @@
46 47 'type' => 'int',
47 48 'default' => Browser_Cache::DEFAULT_ASSET_TTL,
48 49 'min' => 0,
49 50 'max' => 31536000,
50 - 'label' => 'Static asset TTL (seconds)',
51 - 'description' => 'Cache lifetime for CSS, JS, fonts, images. Defaults to 1 year + immutable (the industry-standard "fingerprinted assets never change" pattern).',
51 + 'label' => __( 'Static asset TTL (seconds)', 'xspeed' ),
52 + 'unit' => 'seconds',
53 + 'description' => __( 'Cache lifetime for CSS, JS, fonts, images. Defaults to 1 year + immutable (the industry-standard "fingerprinted assets never change" pattern).', 'xspeed' ),
52 54 'dependsOn' => array( 'field' => 'enabled' ),
53 55 ),
54 56 'html_ttl' => array(
55 57 'type' => 'int',
@@ -55,10 +57,11 @@
55 57 'type' => 'int',
56 58 'default' => Browser_Cache::DEFAULT_HTML_TTL,
57 59 'min' => 0,
58 60 'max' => 31536000,
59 - 'label' => 'HTML TTL (seconds)',
60 - 'description' => 'Cache lifetime for the HTML document itself. Keep short (default 1h) so post edits roll out same-day.',
61 + 'label' => __( 'HTML TTL (seconds)', 'xspeed' ),
62 + 'unit' => 'seconds',
63 + 'description' => __( 'Cache lifetime for the HTML document itself. Keep short (default 1h) so post edits roll out same-day.', 'xspeed' ),
61 64 'dependsOn' => array( 'field' => 'enabled' ),
62 65 ),
63 66 );
64 67 }
@@ -95,25 +98,42 @@
95 98 if ( empty( $opts['enabled'] ) ) {
96 99 return array();
97 100 }
98 101
99 - // Probe whether the snippet has actually been pasted + reloaded.
100 - // If the live HEAD shows Cache-Control: immutable on a known
101 - // static asset, the user is done — suppress the notice. Avoids
102 - // the false-alarm "do something" prompt we used to show forever.
103 - if ( Browser_Cache::probe_headers_present() ) {
102 + // Probe the live response for caching headers on a known static
103 + // asset. Suppress the notice unless the probe PROVES nothing is
104 + // being sent:
105 + //
106 + // true → headers present, from our snippet or from the host's own
107 + // vhost — either way the feature's job is done (issue #329)
108 + // null → the loopback never completed, so we know nothing; a
109 + // broken probe is not evidence of a broken server and must
110 + // not raise a warning the operator cannot act on (issue #18)
111 + // false → proven absent, fall through and show the notice
112 + if ( false !== Browser_Cache::probe_headers_present() ) {
104 113 return array();
105 114 }
106 115
107 - // nginx hosts can't auto-write Cache-Control / Expires headers.
108 - // The directives go into the unified server-block snippet on
109 - // the Cache panel — point users there instead of duplicating the
110 - // snippet here. Topology-aware wording lives in NginxServerBlock.
116 + // nginx hosts can't auto-write Cache-Control / Expires headers, and the
117 + // live probe just confirmed they are NOT being served — so the feature
118 + // reads "enabled" in the dashboard while doing nothing. That is a warning,
119 + // not a passive info note (a token that a user missed on this exact
120 + // account, issue #117): escalate the tone and say plainly that the config
121 + // is configured-but-not-live until the snippet is pasted + nginx reloaded.
122 + // The directives go into the unified server-block snippet on the Cache
123 + // panel — point users there instead of duplicating the snippet here.
111 124 return array(
112 125 array(
113 - 'tone' => 'info',
114 - 'title' => 'nginx server config required',
115 - 'body' => 'Browser-cache headers need to live in your nginx config. Your updated settings are included in the unified server-block snippet on the Cache panel — copy + paste it once into your nginx vhost (or container nginx config), and reload nginx.',
126 + 'tone' => 'warn',
127 + 'title' => __( 'Browser cache is enabled but not active on the server', 'xspeed' ),
128 + 'body' => __( 'Browser-cache headers need to live in your nginx config, and the live response shows they are not being sent yet — so this is on in settings but doing nothing. Your settings are included in the unified server-block snippet on the Cache panel: paste it once into your nginx vhost (or container nginx config) and reload nginx.', 'xspeed' ),
129 + // Lands on the snippet itself rather than on the Cache panel,
130 + // where it is one collapsed section among several (issue #49).
131 + 'action' => Deep_Link::action(
132 + __( 'Go to the snippet', 'xspeed' ),
133 + 'cache',
134 + 'nginx_snippet'
135 + ),
116 136 ),
117 137 );
118 138 }
119 139
@@ -126,8 +146,9 @@
126 146 array(
127 147 'name' => 'xspeed browser-cache',
128 148 'callback' => array( $this, 'cli_handler' ),
129 149 'shortdesc' => 'Print the Apache or nginx browser-cache snippet.',
150 + 'ai_hint' => 'Get the server config snippet that sets browser cache-control headers for static assets. Use when PageSpeed reports "serve static assets with an efficient cache policy", or when the user needs the rules to paste into Apache/nginx.',
130 151 'synopsis' => array(
131 152 array(
132 153 'type' => 'positional',
133 154 'name' => 'flavor',
@@ -151,10 +172,11 @@
151 172 }
152 173 }
153 174
154 175 /**
155 - * Cache-Control / Expires directives for the unified nginx
156 - * server-block snippet. Null when the module is disabled — no
176 + * Cache-Control directives for the unified nginx server-block
177 + * snippet. nginx sends no Expires — `expires off;` pins the block so
178 + * only the explicit `add_header` speaks (#259). Null when the module is disabled — no
157 179 * directives to install.
158 180 */
159 181 public function nginx_directives(): ?string {
160 182 $opts = $this->get_settings();