当 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
