8000 Acorn 5 Overriding Wordpress Cache Headers, Can't Seem to Disable · Issue #456 · roots/acorn · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Acorn 5 Overriding Wordpress Cache Headers, Can't Seem to Disable #456
Closed
@jesstucker

Description

@jesstucker

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfeature/routingIssues or PRs related to routing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0