Chrome and Opera do not respect cache

Asked

Viewed 182 times

4

Chrome and Opera (same engine as the first) does not respect headers Cache-control and Expires, I mean if it’s a link or interaction within the page works normally, this appears ahead:

cache ok

But if the requisition comes of browser bookmarks it simply ignores the cache:

ignorou o cache

It’s almost as if I had pressed F5 (or maybe this is the same behavior), in Firefox the problem does not occur, only in Chrome and even Opera.

The test code was this:

<?php
$seconds = 360; // uma hora de cache

header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $seconds) . ' GMT', true);
header('Cache-Control: public, max-age=' . $seconds, true);
header('Pragma: max-age=' . $seconds, true);

$atual = gmdate('D, d M Y H:i:s');

//Ultima modificação é considerado a hora do acesso
header('Last-Modified: ' . $atual . ' GMT', true);
?>

<a href="pagina.php">Recarregar</a><br>

<?php echo $atual; ?>

This is not a problem with PHP, just use it to test with headers

Is there any way to indicate to the browser through the headers that the cache should "have preference" or this is indeed a Bug?

  • It is some trick programming on the part of the people who maintain these engines. See this question in the matrix OS. The question is 2012, but the answer with more votes has updates 2017.

  • @Renan thank you, I may have read it wrong, but most of the answers were about using F5 and Ctrl+R, but if I do this "Another option is to copy the URL and Paste it in the same tab or Another tab." that the first response suggests the cache is also ignored. Maybe it is my confusion, I will confirm again and warn you

  • 1

    @Renan I understood what happens if I am on a different page and click on the bookmark item to take the page cached then it works, but if I am on the page itself cached and click on the bookmarks or "inputar" the address in the bar it will notice that is the same address and will ignore the cache as probably the browser assumes that you want to update the current page.

  • See if you have anything useful on this https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching

  • I think not, the question is what I said in the previous comment to Renan, I just did not formulate the answer due to lack of time to read the source of Chromium.

No answers

Browser other questions tagged

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