![](/img/trans.png)
[英]http 304 response combined with cache-control does not seem to work with max-age
[英]Cache-Control: public,max-age=LONG_TIME response does not work behind HTTP 301 redirect
我的服务器托管着一个应用程序,该应用程序在每次加载页面时都会预加载100张以上的缩略图。 缩略图图像不会经常更改。
我试图通过使用Cache-Control: public,max-age=MANY_SECONDS
来使连续的缩略图加载更快Cache-Control: public,max-age=MANY_SECONDS
其中MANY_SECONDS
可以使用一年。
通过如下所示的Flask端点请求缩略图:
@app.route('/api/thumbnail/<string:filename>/<int:max_width>/<int:max_height>/')
def api_thumbnail(filename, max_width, max_height):
thumb_filename_template = '{filename}_{orig_digest}-{dimensions}-thumb.png'
# [...] PIL thumbnailing logic [...]
key = Key(thumb_filename_template.format(
filename=filename,
orig_digest=md5_hexdigest_of_original_image,
dimensions='x'.join([max_width, max_height])
))
# Upload the thumbnail image to Amazon S3
key.set_contents_from_string(local_thumbnail_file.read())
redirect(key.generate_url(0, query_auth=False), code=301)
我将所有*-thumb.png
密钥的Cache-Control
标头设置为public,max-age=MANY_SECONDS
,但Firefox仍然针对/api/thumbnail/...
发出请求,并获取301,然后从Amazon S3获取304 。
我的印象是,似乎永久地缓存了301个响应,并且从Amazon S3提供的缩略图文件的Cache-Control
标头应该允许Firefox在本地缓存该缩略图文件长达一年。
所有这些×2的请求确实是开销。 我希望它们被永久保存。
我的解决方案是使用HTML5清单文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.