Closed jkat718 closed 3 years ago
Alternatively, I think a more graceful solution may be to append a random string of numbers to the image's URI's query string after an image is uploaded, and only when that happens. I use this technique in my own development projects to make sure that the browser is loading a fresh script.
E.g. a user uploads an image that gets saved to images/heraldry/player1234.png
. If the upload is successful, the page generated by the server should set the updated image's src
attribute to something like images/heraldry/player1234.png?<random number>
. On subsequent page loads, the query string is not present in the image's src
.
This will ensure that the updated image is loaded and subsequently cached.
This is what I do on the player page in mORK. Since I allow uploads of photos, I make sure the page is displaying the correct one.
The random string would work better, a normal refresh doesn't work most of the time.
PR is ready to go, added string to normal and admin view
Since uploaded images take a while to appear, due to old images lingering in the cache, we could add a message to the effect of "Image uploaded! If new image does not appear, try refreshing the page." when uploading images may help people realize this.
Example:![Annotation 2019-08-28 094913](https://user-images.githubusercontent.com/6913834/63861555-1f9b2d80-c979-11e9-8564-07c37f21ce64.jpg)