Description
Version
5.0.1
What did you expect to happen?
Upgrading from Acorn 4 to 5 would not override Wordpress defaults.
Following the upgrade guide would not cause any regressions.
What actually happens?
My wordpress site's cache headers were overridden, causing page caching to disable.
Steps to reproduce
Migrate acorn 4 site to acorn 5. Follow migration guide.
Note overridden http cache headers:
Acorn 4:
curl --head https://localsite.lndo.site/
...
cache-control: public, max-age=604800
x-varnish: 65559
Acorn 5:
curl --head https://localsite.lndo.site/
...
cache-control: public, max-age=604800, no-cache, private
x-powered-by: Acorn 5.0.1 (Laravel 12.1.1)
x-varnish: 4423764
Did try configuring this in functions.php
add_action('after_setup_theme', function () {
Application::configure()
->withProviders([
App\Providers\ThemeServiceProvider::class,
App\Providers\BlocksServiceProvider::class,
])
->withRouting(wordpress: true)
->withMiddleware(function (Middleware $middleware) {
$middleware->removeFromGroup('wordpress', [
Illuminate\Session\Middleware\StartSession::class,
Illuminate\View\Middleware\ShareErrorsFromSession::class,
]);
$middleware->removeFromGroup('wordpress', [
Illuminate\Http\Middleware\SetCacheHeaders::class,
]);
})
->boot();
}, 0);
Didn't seem to have any effect.
Also tried overriding the headers using an acorn created middleware, this partially worked, but concerned about side effects, and seems buggy (duplicating cache headers):
/mytheme/functions.php
add_action('after_setup_theme', function () {
Application::configure()
->withProviders([
App\Providers\ThemeServiceProvider::class,
App\Providers\BlocksServiceProvider::class,
])
->withRouting(wordpress: true)
->withMiddleware(function (Middleware $middleware) {
$middleware->removeFromGroup('wordpress', [
Illuminate\Session\Middleware\StartSession::class,
Illuminate\View\Middleware\ShareErrorsFromSession::class,
]);
$middleware->appendToGroup('wordpress', [
App\Http\Middleware\CachePolicy::class,
]);
})
->boot();
}, 0);
/mytheme/app/Http/Middleware/CachePolicy.php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class CachePolicy
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$response = $next($request);
return $response->header('Cache-Control','public, max-age=604800');
}
}
Effect:
curl --head https://localsite.lndo.site/
Cache-Control: public, max-age=604800, max-age=604800, public
X-Powered-By: Acorn 5.0.1 (Laravel 12.1.1)
X-Varnish: 622939
Effect on admin:
curl --head https://localsite.lndo.site/wp/wp-admin/
Cache-Control: no-cache, must-revalidate, max-age=0, max-age=604800, public
X-Powered-By: Acorn 5.0.1 (Laravel 12.1.1)
X-Varnish: 622939
Note duplicate header values, also two max-age values when visiting admin.
Thanks,
Jess
System info
No response
Log output
Please confirm this isn't a support request.
Yes