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/BrowserCache/BrowserCacheModule.php +45 -22 1.1.1 → 1.3.7 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,12 @@
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' => __( 'Tells browsers and CDNs how long to keep your files and pages.', 'xspeed' ),
35 + 'group' => 'cache',
34 36 );
35 37 }
36 38
37 39 public function settings_schema(): array {
@@ -38,10 +40,10 @@
38 40 return array(
39 41 'enabled' => array(
40 42 'type' => 'bool',
41 43 '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.',
44 + 'label' => __( 'Enable browser cache headers', 'xspeed' ),
45 + 'description' => __( 'On Apache and LiteSpeed, xSpeed adds the rules to .htaccess for you. On nginx, you copy the snippet into your server config.', 'xspeed' ),
44 46 ),
45 47 'asset_ttl' => array(
46 48 'type' => 'int',
47 49 'default' => Browser_Cache::DEFAULT_ASSET_TTL,
@@ -46,10 +48,11 @@
46 48 'type' => 'int',
47 49 'default' => Browser_Cache::DEFAULT_ASSET_TTL,
48 50 'min' => 0,
49 51 '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).',
52 + 'label' => __( 'File lifetime (seconds)', 'xspeed' ),
53 + 'unit' => 'seconds',
54 + 'description' => __( 'How long browsers keep CSS, JS, fonts and images. The default is 1 year, which suits files that change name when they change.', 'xspeed' ),
52 55 'dependsOn' => array( 'field' => 'enabled' ),
53 56 ),
54 57 'html_ttl' => array(
55 58 'type' => 'int',
@@ -55,10 +58,11 @@
55 58 'type' => 'int',
56 59 'default' => Browser_Cache::DEFAULT_HTML_TTL,
57 60 'min' => 0,
58 61 '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.',
62 + 'label' => __( 'Page lifetime (seconds)', 'xspeed' ),
63 + 'unit' => 'seconds',
64 + 'description' => __( 'How long browsers keep the page itself. Keep it short (default 1 hour) so visitors see your edits the same day.', 'xspeed' ),
61 65 'dependsOn' => array( 'field' => 'enabled' ),
62 66 ),
63 67 );
64 68 }
@@ -95,25 +99,42 @@
95 99 if ( empty( $opts['enabled'] ) ) {
96 100 return array();
97 101 }
98 102
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() ) {
103 + // Probe the live response for caching headers on a known static
104 + // asset. Suppress the notice unless the probe PROVES nothing is
105 + // being sent:
106 + //
107 + // true → headers present, from our snippet or from the host's own
108 + // vhost — either way the feature's job is done (issue #329)
109 + // null → the loopback never completed, so we know nothing; a
110 + // broken probe is not evidence of a broken server and must
111 + // not raise a warning the operator cannot act on (issue #18)
112 + // false → proven absent, fall through and show the notice
113 + if ( false !== Browser_Cache::probe_headers_present() ) {
104 114 return array();
105 115 }
106 116
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.
117 + // nginx hosts can't auto-write Cache-Control / Expires headers, and the
118 + // live probe just confirmed they are NOT being served — so the feature
119 + // reads "enabled" in the dashboard while doing nothing. That is a warning,
120 + // not a passive info note (a token that a user missed on this exact
121 + // account, issue #117): escalate the tone and say plainly that the config
122 + // is configured-but-not-live until the snippet is pasted + nginx reloaded.
123 + // The directives go into the unified server-block snippet on the Cache
124 + // panel — point users there instead of duplicating the snippet here.
111 125 return array(
112 126 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.',
127 + 'tone' => 'warn',
128 + 'title' => __( 'Browser cache is enabled but not active on the server', 'xspeed' ),
129 + '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' ),
130 + // Lands on the snippet itself rather than on the Cache panel,
131 + // where it is one collapsed section among several (issue #49).
132 + 'action' => Deep_Link::action(
133 + __( 'Go to the snippet', 'xspeed' ),
134 + 'cache',
135 + 'nginx_snippet'
136 + ),
116 137 ),
117 138 );
118 139 }
119 140
@@ -126,8 +147,9 @@
126 147 array(
127 148 'name' => 'xspeed browser-cache',
128 149 'callback' => array( $this, 'cli_handler' ),
129 150 'shortdesc' => 'Print the Apache or nginx browser-cache snippet.',
151 + '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 152 'synopsis' => array(
131 153 array(
132 154 'type' => 'positional',
133 155 'name' => 'flavor',
@@ -151,10 +173,11 @@
151 173 }
152 174 }
153 175
154 176 /**
155 - * Cache-Control / Expires directives for the unified nginx
156 - * server-block snippet. Null when the module is disabled — no
177 + * Cache-Control directives for the unified nginx server-block
178 + * snippet. nginx sends no Expires — `expires off;` pins the block so
179 + * only the explicit `add_header` speaks (#259). Null when the module is disabled — no
157 180 * directives to install.
158 181 */
159 182 public function nginx_directives(): ?string {
160 183 $opts = $this->get_settings();