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

后端 未结 3 878
名媛妹妹
名媛妹妹 2020-12-15 23:23

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

P.S.: It is

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 23:43

    Laravel 5.5 <

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

    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
    ];
    

提交回复
热议问题