【问题标题】:Cache-Control: public,max-age=LONG_TIME response does not work behind HTTP 301 redirectCache-Control: public,max-age=LONG_TIME 响应在 HTTP 301 重定向后不起作用
【发布时间】:2013-08-21 11:20:41
【问题描述】:

我的服务器正在托管一个应用程序,该应用程序在每次加载页面时预加载 >100 个缩略图。缩略图不经常更改。

我正在尝试通过使用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 在本地缓存缩略图文件长达一年。

所有这些 thumbs × 2 请求确实是开销。我希望它们永久缓存。

【问题讨论】:

    标签: http firefox web-applications browser-cache cache-control


    【解决方案1】:

    我的解决方案是使用HTML5 manifest 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-19
      • 2021-04-15
      • 1970-01-01
      • 2020-08-11
      • 2022-01-22
      • 2015-04-08
      • 1970-01-01
      • 2012-06-30
      相关资源
      最近更新 更多