Hello. The problem is: there is a user page. When updating an avatar or cover, a new image is accepted in the controller, resized, it is saved to a folder on the server. Folder with user id. The image overwrites the existing, that is, is saved under the same name 'avatar.jpg'. After that, a forced redirect to the user page. But the image does not change. It only changes if you press ctrl + F5. How to deal with it? Already registered in head such lines:

<meta http-equiv="cache-control" content="max-age=0" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="expires" content="0" /> <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> <meta http-equiv="pragma" content="no-cache" /> 

But nothing has changed. I will welcome any advice. If you need more information - I will provide.

  • And you do not overwrite, and make a new link to the avatar - andreymal
  • @andreymal can store the name of the avatar in the database then? - Dmitry
  • That's what they do - andreymal
  • @andreymal oh, then good, thanks) But I still wonder why. - Dmitriy
  • and these are new chrome pens. They have some new feature with enhanced caching - n.osennij

1 answer 1

When creating a link to the avatar, add a timestamp to it, for example:

 $avatar = '<img src="'.'URL_TO_AVATAR'.'?t='.filemtime('PATH_TO_FILE_OF_AVATAR')).'" alt="">'; 

then when overwriting a file, the time returned by the filemtime () function will change, which will change the link to the avatar.

  • thank you very much! - Dmitriy
  • @Visman, a filemtime not "heavy"? Will it be optimal to store the timestamp in the database? - br3t
  • It is not heavy. Brakes on the forums using this method is not seen. - Visman
  • one
    @ br3t, although using apache / nginx would be better to give the necessary headers, I think. - Visman
  • @Visman is actually more powerful over time. The main advantage is that you can set up resources (headers) for "perpetual" caching, thereby drastically reducing the number of requests to the server without shifting to the user such actions as cleaning the cache. - Pavel Mayorov