I use Laravel 3
in a certain system that we develop here in the company.
I need every time the application version changes, all users' caches to be updated.
The programmers here already wanted to use that old tactic to put an interrogation in front of the urls of css
and js
, however this is out of hand since there are many styles used.
I had the idea of defining the header that removes the cache (everyone says that it works), which would appear only when the application was updated to the user.
The problem is that it was found that this did not work in any of the tests performed.
The code I have is the following:
Route::filter('after', function ($response)
{
$headers = $response->foundation->headers;
$version = Config::get('application.version');
$headers->set('X-App-Version', $version);
if (Cookie::get('version') != $version || Config::get('error.detail') == true) {
$headers->addCacheControlDirective('no-cache', true);
$headers->addCacheControlDirective('max-age', 0);
$headers->addCacheControlDirective('must-revalidate', true);
$headers->addCacheControlDirective('no-store', true);
Cookie::forever('version', $version, URI::current());
}
});
This adds the following headers:
Cache-Control:max-age=0, must-revalidate, no-cache, no-store, private
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:37316
Content-Type:text/html; charset=UTF-8
Date:Mon, 19 Oct 2015 11:20:08 GMT
Keep-Alive:timeout=5, max=38
Server:Apache/2.4.7 (Ubuntu)
Set-Cookie:version=a5b7217bab8d25e470fa89b6301b6bbe06f9f96e%2B4.5; expires=Sat, 17-Oct-2020 11:20:08 GMT; Max-Age=157679999; path=beneficiario/novidades; httponly
Set-Cookie:nome_do_cookie=03198b561773a09d98d02491766970391b1d8e71%2BWwwUrV5Z94PdQcmKBDMDxpOvjFyfK1NvFp1l4PTQ; path=/; httponly
Vary:Accept-Encoding
X-App-Version:4.5
X-Powered-By:PHP/5.5.9-1ubuntu4.11
As far as I know, this should work so that the entire browser cache is reset.
After all, is there an error in my code, or is it really that definition of headers to define if the content will have the browser cache or does it vary from browser to browser?