Reputation: 91
I have a website where users can upload their profile picture which is visible to other users. I want the browser to cache these pictures, but if the user changed his picture, retrieve it again. How could I do that? Thank you.
Example: I open a page and there are many profile pictures. The browser re-downloads only these profile pictures that have been changed.
Upvotes: 0
Views: 179
Reputation: 3339
Implement the entity tag. Simply the put the timestamp as etag when the profile pic gets changed
Entity Tags are a way of incorporating caching into the HTTP Protocol. When a server returns a response it can attach an ETagheader which gives a value which represents the state of the object returned in response to the client's request.
When the client makes requests for the same response next time,it can sends back the ETag in it's request and the server can compare if it is same. If its same , you will send 304 response so browser will use the cached copy. You just need to change this value of E Tag every time, when profile pics get modified. So, when user first time acess the page, he get picture with some E Tag. In mean time, if some pictures got updated you have to change,its E Tag value, so next time user loads that page, only changed images needs to download.
http://en.wikipedia.org/wiki/HTTP_ETag
Upvotes: 1