A
A
Alexey2016-10-30 19:51:47
JavaScript
Alexey, 2016-10-30 19:51:47

How to defeat the browser cache after loading a new image?

Hello! The user uploads an avatar via ajax, while the file name on the server does not change. How, in this case, to make sure that after replacing the image, it is taken not from the cache, but from the server?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
T_y_l_e_r, 2016-10-30
@T_y_l_e_r

Append random numbers to the end of the filename.
img.png?352637362 Dynamically
change the contents of src img to a new url, you can even change the entire img tag using innerHTML

I
iBird Rose, 2016-10-30
@iiiBird

You still have to change the path to the image. for example, it is good practice to write in the form img/avatar.png?ver-2

V
Valery, 2016-10-31
@supervaleha

The correct way is to add pseudo-random code to the file. Timestamp, for example.
This will not affect the display, but the browser will assume that a NEW photo is loaded each time.
For example,image.png?t=12328736467536

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question