Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jimmitjoo's avatar

Filament and Gzip content issue

I have installed Filament in an existing project I have. When logging in and viewing the admin dashboard, just the left menu "dashboard" and the "app name" in top left is loaded. When inspecting the dom though, everything is there, but nothing is visible. I do not find anything hiding it either.

So I have experimented by removing middlewares and found out that it is my GzipEncode middleway causing issues. When removing it, everything works great. But I do not know why. Can you help me out what is interfering with Filament in the following?

Thanks.

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

        if (in_array('gzip', $request->getEncodings()) && function_exists('gzencode')) {
            $response->setContent(gzencode($response->getContent(), 9));
            $response->headers->add([
                'Content-Encoding' => 'gzip',
                'X-Vapor-Base64-Encode' => 'True',
            ]);
        }
        return $response;
    }
}
0 likes
3 replies
LaryAI's avatar
Level 58

It seems like the issue you're encountering is related to the GzipEncodeResponse middleware that is compressing the response content. However, it's important to ensure that the response is only compressed when the client can handle it and when the response has not already been compressed. Additionally, you should only compress responses with a content type that benefits from Gzip, such as text-based content.

Here's an updated version of your middleware that includes checks for the content type and ensures that the response is not already encoded:

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

        // Only compress text-based responses
        $contentType = $response->headers->get('Content-Type');
        if (strpos($contentType, 'text/') === false && strpos($contentType, 'json') === false) {
            return $response;
        }

        // Check if the response should be Gzip encoded
        if (!$response->headers->has('Content-Encoding') &&
            in_array('gzip', $request->getEncodings()) &&
            function_exists('gzencode') &&
            !$response->isRedirection() &&
            ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300)
        ) {
            $content = gzencode($response->getContent(), 9);
            $response->setContent($content);
            $response->headers->set('Content-Encoding', 'gzip');
            $response->headers->set('Vary', 'Accept-Encoding', false);
            $response->headers->set('Content-Length', strlen($content));
        }

        return $response;
    }
}

Here are the changes made:

  1. Added a check for the content type to ensure we're only compressing text-based content (text/* and application/json).
  2. Added a check to ensure the response is not already encoded (Content-Encoding header is not set).
  3. Added a check to ensure we're not compressing redirections or responses with status codes outside the 200 range.
  4. Set the Vary header to Accept-Encoding to inform caches that the response varies based on the Accept-Encoding request header.
  5. Updated the Content-Length header with the length of the compressed content.

Make sure to test this updated middleware thoroughly to ensure it works as expected with your application and does not interfere with Filament or any other part of your application.

ksimenic's avatar

This is actually a Livewire issue. You can solve it with following steps:

  1. Publish livewire configuration - https://livewire.laravel.com/docs/installation#publishing-the-configuration-file
  2. Manually include livewire's fronted assets - https://livewire.laravel.com/docs/installation#manually-including-livewires-frontend-assets
class AdminPanelProvider extends PanelProvider
{
	public function panel(Panel $panel): Panel
    {
		...
    }

    public function register(): void
    {
        parent::register();

        FilamentView::registerRenderHook('panels::head.end', fn (): string => Blade::render('@livewireStyles'));
        FilamentView::registerRenderHook('panels::body.end', fn (): string => Blade::render('@livewireScripts'));
    }

Please or to participate in this conversation.