gpt4 book ai didi

python - 使用 BottlePy/GAE 进行浏览器缓存

转载 作者:太空宇宙 更新时间:2023-11-04 01:40:16 24 4
gpt4 key购买 nike

我在我的网站上运行 Google Page Speed,它是在 Google App Engine 上的 Python/Bottle 中。

它说:'以下可缓存资源的新鲜度很短。为以下资源指定至少一周后到期:'

然后接着列出我的大部分静态文件(图片、css、js),还说要指定缓存一个多星期。

在我的 app.yaml 文件中,我有这个:default_expiration: "21d 1h"它似乎没有做任何事情。

有没有人知道我如何缓存它正在谈论的文件,或者这是在 AppEngine 上使用 Bottle 的问题吗?

最佳答案

如果你的代码中有这个:

@bottle.route('/static/:filename#.*#')
def static(filename):
return bottle.static_file(filename, root='./static/')

你可以添加:

response.headers['Cache-Control'] = 'public, max-age=SECONDS'

return 前面启用浏览器缓存。只要您不使用 cookie 或 GET 参数,这也适用于动态生成的页面。

但如果可以的话,您应该让 GAE 直接提供静态文件。

关于python - 使用 BottlePy/GAE 进行浏览器缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5875171/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com