Send a "304 Not Modified" for images stored in the datastore
Posted
by Emilien
on Stack Overflow
See other posts from Stack Overflow
or by Emilien
Published on 2010-05-01T17:27:14Z
Indexed on
2010/05/01
17:47 UTC
Read the original article
Hit count: 294
I store user-uploaded images in the Google App Engine datastore as db.Blob
, as proposed in the docs. I then serve those images on /images/<id>.jpg
.
The server always sends a 200 OK
response, which means that the browser has to download the same image multiple time (== slower) and that the server has to send the same image multiple times (== more expensive).
As most of those images will likely never change, I'd like to be able to send a 304 Not Modified
response. I am thinking about calculating some kind of hash of the picture when the user uploads it, and then use this to know if the user already has this image (maybe send the hash as an Etag
?)
I have found this answer and this answer that explain the logic pretty well, but I have 2 questions:
- Is it possible to send an
Etag
in Google App Engine? - Has anyone implemented such logic, and/or is there any code snippet available?
© Stack Overflow or respective owner