Browser Cache issues in Laravel 4 Application

*爱你&永不变心* 提交于 2019-12-04 08:39:30
Rico Leuthold

EDIT:

Surprise, surprise - the previous solution did not work in IE.

After spending another couple of hours I ended up adding the following to the blade template header:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="cache-control" content="no-store" />
<meta http-equiv="cache-control" content="must-revalidate" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

This seems to work for all browsers.

Furthermore, I had to prevent caching of all AJAX calls. This question provided some very useful answers.

The following does not work in IE:

I've found a solution - not a pretty one in my opinion.

Using a (global after) filter as follows ...

App::after(function($request, $response)
{
    // prevent browser caching
    $response->headers->set('Cache-Control','nocache, no-store, max-age=0, must-revalidate');
    $response->headers->set('Pragma','no-cache');
    $response->headers->set('Expires','Fri, 01 Jan 1990 00:00:00 GMT');
});

seems to force the browser to reload the page from the server.

The answers to this question provided some very useful information.

However, I'm still wondering why other developers do not have the same problem or if they have, how they solve it.

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