The most guaranteed way is to add a new parameter to the image link. Example: imagem.jpg?20170724
. If you modify tomorrow it would look something like imagem.jpg?20170725
.
You can try all these tricks with header()
but it will not always work in all browsers as you can see. In 18 years dealing with this, I tried all these header pragma
, h eader expires
and header macumba vela preta
, and when I thought I'd found the right combination, a browser update would turn everything off. I simply gave up and opted for the simplest and obvious that is to add the file version as a parameter or the last modified date and time.
In the database, create a field "date_modified" and whenever you search the image, also read this field to concatenate it in the URL.
Another technique used is to generate a file with a new unique name. So you would not have to worry about putting the date or version as a parameter of the URL. The disadvantage of this is if the image is used for SEO because the previous one is given as Not found by the search engines and the site loses rankings in the search for images (google images, for example). >
Note that the parameterized technique does not update the existing cache. What happens is that the cache remains and the new file is downloaded because to the browser, 1 different parameter is given as new file.