← All changes
|
includes/modules/BrowserCache/BrowserCacheModule.php
+36
-22
1.1.2
→
1.3.2
View file →
| @@ -28,11 +28,11 @@ | ||
| 28 | 28 | public const VERSION = '1.0.0'; |
| 29 | 29 | |
| 30 | 30 | public function ui_metadata(): array { |
| 31 | 31 | return array( |
| 32 | - 'label' => 'Browser Cache', | |
| 32 | + 'label' => __( 'Browser Cache', 'xspeed' ), | |
| 33 | 33 | 'icon' => 'Clock', |
| 34 | - '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' ), | |
| 35 | 35 | ); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function settings_schema(): array { |
| @@ -39,10 +39,10 @@ | ||
| 39 | 39 | return array( |
| 40 | 40 | 'enabled' => array( |
| 41 | 41 | 'type' => 'bool', |
| 42 | 42 | 'default' => false, |
| 43 | - 'label' => 'Enable browser cache headers', | |
| 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.', | |
| 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' ), | |
| 45 | 45 | ), |
| 46 | 46 | 'asset_ttl' => array( |
| 47 | 47 | 'type' => 'int', |
| 48 | 48 | 'default' => Browser_Cache::DEFAULT_ASSET_TTL, |
| @@ -47,10 +47,11 @@ | ||
| 47 | 47 | 'type' => 'int', |
| 48 | 48 | 'default' => Browser_Cache::DEFAULT_ASSET_TTL, |
| 49 | 49 | 'min' => 0, |
| 50 | 50 | 'max' => 31536000, |
| 51 | - 'label' => 'Static asset TTL (seconds)', | |
| 52 | - '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' ), | |
| 53 | 54 | 'dependsOn' => array( 'field' => 'enabled' ), |
| 54 | 55 | ), |
| 55 | 56 | 'html_ttl' => array( |
| 56 | 57 | 'type' => 'int', |
| @@ -56,10 +57,11 @@ | ||
| 56 | 57 | 'type' => 'int', |
| 57 | 58 | 'default' => Browser_Cache::DEFAULT_HTML_TTL, |
| 58 | 59 | 'min' => 0, |
| 59 | 60 | 'max' => 31536000, |
| 60 | - 'label' => 'HTML TTL (seconds)', | |
| 61 | - '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' ), | |
| 62 | 64 | 'dependsOn' => array( 'field' => 'enabled' ), |
| 63 | 65 | ), |
| 64 | 66 | ); |
| 65 | 67 | } |
| @@ -96,25 +98,35 @@ | ||
| 96 | 98 | if ( empty( $opts['enabled'] ) ) { |
| 97 | 99 | return array(); |
| 98 | 100 | } |
| 99 | 101 | |
| 100 | - // Probe whether the snippet has actually been pasted + reloaded. | |
| 101 | - // If the live HEAD shows Cache-Control: immutable on a known | |
| 102 | - // static asset, the user is done — suppress the notice. Avoids | |
| 103 | - // the false-alarm "do something" prompt we used to show forever. | |
| 104 | - 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() ) { | |
| 105 | 113 | return array(); |
| 106 | 114 | } |
| 107 | 115 | |
| 108 | - // nginx hosts can't auto-write Cache-Control / Expires headers. | |
| 109 | - // The directives go into the unified server-block snippet on | |
| 110 | - // the Cache panel — point users there instead of duplicating the | |
| 111 | - // 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. | |
| 112 | 124 | return array( |
| 113 | 125 | array( |
| 114 | - 'tone' => 'info', | |
| 115 | - 'title' => __( 'nginx server config required', 'xspeed' ), | |
| 116 | - '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.', 'xspeed' ), | |
| 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' ), | |
| 117 | 129 | // Lands on the snippet itself rather than on the Cache panel, |
| 118 | 130 | // where it is one collapsed section among several (issue #49). |
| 119 | 131 | 'action' => Deep_Link::action( |
| 120 | 132 | __( 'Go to the snippet', 'xspeed' ), |
| @@ -134,8 +146,9 @@ | ||
| 134 | 146 | array( |
| 135 | 147 | 'name' => 'xspeed browser-cache', |
| 136 | 148 | 'callback' => array( $this, 'cli_handler' ), |
| 137 | 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.', | |
| 138 | 151 | 'synopsis' => array( |
| 139 | 152 | array( |
| 140 | 153 | 'type' => 'positional', |
| 141 | 154 | 'name' => 'flavor', |
| @@ -159,10 +172,11 @@ | ||
| 159 | 172 | } |
| 160 | 173 | } |
| 161 | 174 | |
| 162 | 175 | /** |
| 163 | - * Cache-Control / Expires directives for the unified nginx | |
| 164 | - * 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 | |
| 165 | 179 | * directives to install. |
| 166 | 180 | */ |
| 167 | 181 | public function nginx_directives(): ?string { |
| 168 | 182 | $opts = $this->get_settings(); |