Send a “304 Not Modified” for images stored in the datastore

前端 未结 4 2066
迷失自我
迷失自我 2021-02-04 20:43

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/.jpg

4条回答
  •  盖世英雄少女心
    2021-02-04 21:09

    There might be a simpler solution here. This requires that you never overwrite the data associated with any identifier, e.g. modifying the image would create a new id (and hence a new URL).

    Simply set the Expires header from your request handler to the far future, e.g. now + a year. This would result in clients caching the image and not asking for an update until that time comes.

    This approach has some tradeoffs, like ensuring new URLs are embedded when images are modified, so you have to decide for yourself. What jbochi is proposing is the other alternative that puts more logic into the image request handler.

提交回复
热议问题