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

后端 未结 3 876
名媛妹妹
名媛妹妹 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条回答
  •  生来不讨喜
    2020-12-15 23:55

    For people that seek a way to write less code, here is another way you can add headers to a response without extra steps.

    In the example above, I created a middleware to prevent routes from being cached in the end user browser.

    withHeaders([
                "Pragma" => "no-cache",
                "Expires" => "Fri, 01 Jan 1990 00:00:00 GMT",
                "Cache-Control" => "no-cache, must-revalidate, no-store, max-age=0, private",
            ]);
        }
    }
    

    Source: Attaching Headers To Responses

提交回复
热议问题