D
D
danil_gazizov2015-12-31 09:58:08
Browsers
danil_gazizov, 2015-12-31 09:58:08

How to organize competent caching of user avatars?

The question is obscenely stupid. Users register on the site, upload their photos, write posts. Each post stores the user id, and the link to the author's photo is generated as http://sayt.ru/user/ <userid> /photo.png
But here's the trouble - the photos of the authors, of course, are cached by the browser. And when you change someone's photo, it certainly will not be updated.
The question is - how to do these things "wisely" so that the pictures are relevant? What is the correct approach to deal with this issue?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
P
Pavel Solovyov, 2015-12-31
@pavel_salauyou

generate a unique name for the photo each time, and store the user's ID in the link, bad practice.

E
Eugene, 2015-12-31
@Nc_Soft

The best option is a unique name for the file.
Worse option: /user/userId/photo.png?lastModify

3
386DX, 2015-12-31
@386DX

habrahabr.ru/post/109043
www.feedthebot.com/tools/if-modified
there is this

D
danil_gazizov, 2015-12-31
@danil_gazizov

Everything got to me!!
1. I will set up the user.lastupdate field - I will record the moment of the last profile changes.
2. When uploading a new avatar, change this lasupdate = now()
3. When issuing user posts, along with the author's id, I will also issue user.lastupdate
4. I will generate avatar url as /user/userid/photo.png?<user. last update>

V
Vova, 2015-01-02
@vovko

danil_gazizov you can also keep the version of the picture, instead of last_update -> version, an integer that can be incremented after each update, /photo.png?8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question