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

twols's avatar
Level 1

Browser caching for images

Hello guys, I'm trying to understand how to get my dynamic generated images cached by the browser.

The image is available only for logged in user and delivered like this:

        $img = Image::cache(function ($image) use ($user, $w, $h) {
            return $image->make(Storage::get('avatars/'.$user->avatar))->fit($w, $h);
        });

        return Response::make($img, 200, array(
            'Content-Type' => 'image/jpg'
        ));

The browser is always getting the response 200 and is not caching the image. How can I fix that? Is there any way in Laravel to set the lifetime or return something like "not modified" flag?

0 likes
1 reply

Please or to participate in this conversation.