How to disable page caching

Asked

Viewed 499 times

0

I have a page that saves the user’s photo, when editing the photo the cache always keeps taking the old photo to display. I’ve tried using : and tried to use some variations of it and it doesn’t work. Does anyone know any other way?

  • You can use the photo name with the suffix based on the timestamp of the last update, for example <img src="foto.jpg?<?=filemtime('foto.jpg');?>">, so every time you update the photo filemtime will be different, which changes the URL and bypasses the cache, as I explained in the answer: https://answall.com/a/169846/3635

1 answer

0

There is a very simple way to bypass browser caching, if you change the image name the browser will "think" that it is a new image and does not cache the old one.

Another option is in the file .htaccess add this rule

<FilesMatch "\.(gif|ico|jpe|jpeg|jpg|js|png)$">
    <IfModule mod_expires.c>
        ExpiresActive Off
    </IfModule>
    <IfModule mod_headers.c>
        FileETag None
        Header unset ETag
        Header unset Pragma
        Header unset Cache-Control
        Header unset Last-Modified
        Header set Pragma "no-cache"
        Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
        Header set Expires "Mon, 10 Apr 1972 00:00:00 GMT"
    </IfModule>
</FilesMatch>

Browser other questions tagged

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