Why even set the headers the page cache is not updated?

Asked

Viewed 121 times

1

Use the Laravel 3 in a certain system that we develop here in the company.

I need that every time the application version changes, the cache of all users be updated.

The programmers here have already wanted to use that old tactic of putting a question in front of the urls of the css and js, but this is out of hand as are many styles used.

I had the idea to set the header that removes the cache (everyone around says 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 this::

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, there is some error in my code, or actually this definition of headers to define whether the content will have browser cache or does not vary from browser to browser?

  • is to update the cache of css and js files? I don’t understand the difficulty or difficulty in using the argumentator parameter (?)

  • @Danielomine, there’s just no way! It’s multiple templates, multiple views, multiple css and js. There’s no way to run this. And let’s agree that this is gambiarra! For development goes up, but for production I do not agree no.

  • @Danielomine, I understand. I say that is gambiarra why set one by one! I’m almost thinking about changing the source code of the Laravel (more gambiarra yet) so that it is already implemented automatically. Or create a function through the macro, which does this. It’s an idea to think about. Even so I keep asking the question, because I want to know the reason why time works, not time.

  • Not read with Laravel, but I believe that in Laravel should have the helpers for this. Every framework should have a feature of this type. But if you have already set up outside the appropriate HTML helper, there is no way, you will have to redo everything in the rsrsrr nail.. Good that already you are correcting and doing with some helper, if it exists in Laravel

  • There is the macro @Danielomine. With macros I can create a magic method within the class at runtime. Hence I use it instead of using the pattern.

  • 1

    http://laravel.io/forum/03-11-2014-any-l4-mechanism-to-assist-with-version-of-css-js?page=1

  • @Danielomine, exactly what I’m reading now.

  • you can also try using url rewrite, where anything that is . css and . js would be overwritten by adding the argumentator.. In a way it is invisible to the user. Only the compiler of the browser sees. But then at that point, although it is clean and elegant, it is a rather coarse and rather coarse gambiarra. rsrs but it works.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.