[6.x] Add cache-control header to cached content#11430
[6.x] Add cache-control header to cached content#11430indykoning wants to merge 10 commits intostatamic:6.xfrom
Conversation
|
This PR should now be ready to merge now, it is currently in use without any issues 🙂 |
Calling this check triggers the ETag matching, and sets the notModified response code if a match is found. If https://github.com/laravel/framework/blob/12.x/src/Illuminate/Http/Middleware/CheckResponseForModifications.php is in the middleware stack it would do it too, it is not in the stack by default. And checking multiple times causes no issues
| } | ||
|
|
||
| if ($response = $this->attemptToServeCachedResponse($request)) { | ||
| $response->isNotModified($request); |
There was a problem hiding this comment.
This is a check from the Symfony response: https://github.com/symfony/symfony/blob/b5b0cbf0acb520629cc72532f99728e31992a55f/src/Symfony/Component/HttpFoundation/Response.php#L1113
It checks the etags on the request and response to determine if the local cache is still valid after the expiration time.
If it is, it will empty the response body and set the response code to 304 Not Modified. Saving the (Kilo)bytes from having to be downloaded again if they haven't changed.
Laravel also has a middleware that does this https://github.com/laravel/framework/blob/12.x/src/Illuminate/Http/Middleware/CheckResponseForModifications.php however it is not loaded by default.
It causes no issues if the check is called multiple times.
Closes statamic/ideas#1309
Half and full caching strategies will get these improvements if these are pages that can be cached.
This PR will add cache-control public headers for pages that can be/will be/have been cached or have been served from cache if the webserver wasn't configured properly or query params did not match.
It can improve experienced speed and reduce server load by using local copies of statically cached content. And if combined with a properly configured CDN which supports caching pages can reduce server load as the CDN will serve the page and occasionally update it's cache.
(If you're using a CDN in-between you might not even need the full strategy anymore)Edit: ^ That is not true (yet) since it still requires the csrf token + session, cookies will be sent. Which means CDNs will not cache unless specifically instructed to ignore the cookies