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

Ligonsker's avatar

How can I make the browser read the new file and not the cached (and deleted) one?

Hi,

I am displaying a pdf in the web browser using the response helper:

public function view_pdf(Request $request)
{
    $full_path = Storage::disk('disk_1')->path('some_pdf.pdf');
    return response()->file($full_path);
}

But if I replace the pdf file in that folder with the same name, it would still display the old file because it's saved in the browser's cache. Is there anything to do to send the new file? Maybe a header with the response?

Thanks

0 likes
3 replies
Ligonsker's avatar

@jlrdw Awesome, going to try it, looks like it might be it. thank you

2 likes
Ligonsker's avatar

@jlrdw Update: I had to change the syntax in the old SO answer a bit to make the Cache-Control header be set instead of the default one:

return response()->file($full_path, ['Cache-Control' =>  'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0']);

I am sending a key-value array (header-key/header value) as the second arguement of the file() method

1 like

Please or to participate in this conversation.