1

I have a controller that serves images from my Laravel storage folder:

public function showPhoto($filename)
{
    return Image::make(storage_path('app/images/' . $filename))->response();
}

My question: How can I enable browser cache for this images? I have seen the package intervention/imagecache, but I doesn't mean server cache.

I have changed things like response status 304, but that doesn't work. How can I have browser cache for this images?

angelique000
  • 815
  • 2
  • 9
  • 22
  • You need to send few headers along with the image as response. Take a look at https://stackoverflow.com/questions/49547/how-to-control-web-page-caching-across-all-browsers – Panther Oct 04 '17 at 17:17

1 Answers1

0

I had the same problem today, you simply need to add setClientTtl($cacheInSeconds) at the end of your call, like so:

return Image::make(storage_path('app/images/' . $filename))
    ->response()
    ->setClientTtl(60 * 60 * 24 * 7); // cache for 1 week
spaceemotion
  • 1,140
  • 3
  • 18
  • 29