0

We have this middleware in my app because internal security asked us to overwrite these response headers.

class NoCacheControlHeaders
{
    public function handle(Request $request, Closure $next)
    {
        $response = $next($request);

        $response->headers->set('Pragma', 'no-cache');
        $response->headers->set('Expires', '0');
        $response->headers->set('Cache-Control', 'max-age=0, must-revalidate, no-cache, no-store, no-transform, private');

        return $response;
    }
}

Suddenly after upgrade of Livewire to version 3 it doesnt work. HTTP response contain these headers:

Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Cache-Control: max-age=0, must-revalidate, no-cache, no-store, private

I set my NoCacheControlHeaders middleware to be executed as last one in Http/Kernel.php's $middlewarePriority, but it doesnt help.

1 Answer 1

1

Turns out Livewire 3 has a feature called DisableBackButtonCache which uses livewire/src/Features/SupportDisablingBackButtonCache/DisableBackButtonCacheMiddleware.php middleware to overwrite the headers.

At the time of writing this post there is no option to customize the headers or to turn this feature off in config.

However it can be turned of for every component at runtime on mount event. Add this to your AppServiceProvider.php:boot():

Livewire::listen('mount', function ($component) {
    $component->enableBackButtonCache();
});

GitHub discussion: https://github.com/livewire/livewire/discussions/8198

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.