gpt4 book ai didi

python - Tornado 将查询字符串添加到静态文件路径

转载 作者:太空宇宙 更新时间:2023-11-04 03:47:31 26 4
gpt4 key购买 nike

当 tornado 加载模板时,静态文件路径变成这样:

http://localhost:8888/static/js/jquery-ui.min.js?v=02e1058fd3cb0799867ba932a4ad3b22

我使用这种声明静态文件的方法:

settings = {
'static_path': os.path.join(os.getcwd(), 'static'),
}
application = tornado.web.Application([
(r'/', MainHandler),
(r'/login/', LoginHandler),
(r'/websocket', EchoWebSocket),
(r'/static/', tornado.web.StaticFileHandler, dict(path=settings['static_path'])),
], static_hash_cache=False, debug=True, cookie_secret='salt', **settings)

如何去掉路径中的“v”变量?

最佳答案

v是tornado根据文件内容生成的静态文件hash。

The static_url() function will translate that relative path to a URI that looks like /static/images/logo.png?v=aae54. The v argument is a hash of the content in logo.png, and its presence makes the Tornado server send cache headers to the user’s browser that will make the browser cache the content indefinitely.

Since the v argument is based on the content of the file, if you update a file and restart your server, it will start sending a new v value, so the user’s browser will automatically fetch the new file. If the file’s contents don’t change, the browser will continue to use a locally cached copy without ever checking for updates on the server, significantly improving rendering performance.

v 用于在客户端浏览器中缓存文件。你可以想象这是文件名的一部分。

如果你不想这样,正如tornado所说,你可以使用nginx服务器。

http://www.tornadoweb.org/en/branch2.3/overview.html#static-files-and-aggressive-file-caching

关于python - Tornado 将查询字符串添加到静态文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23003649/

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