Laravel 5.5 how to set Cache-Control HTTP header globally?

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

My Laravel application ist returning Cache-Control: no-cache, private HTTP header by default for each site. How can I change this behaviour?

P.S.: It is not a PHP.ini problem, because changing session.cache_limiter to empty/public does not change anything.

回答1:

You can have a global middleware for that. something like:

<?php  namespace App\Http\Middleware;  use Closure;  class CacheControl {     public function handle($request, Closure $next)     {         $response = $next($request);          $response->header('Cache-Control', 'no-cache, must-revalidate');         // Or whatever you want it to be:         // $response->header('Cache-Control', 'max-age=100');          return $response;     } } 

then just register this as a global middleware in the Kernel file:

protected $middleware = [     ....     \App\Http\Middleware\CacheControl::class ]; 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!