Reputation: 918
When tornado loads a template, the static files path turns into something like this:
http://localhost:8888/static/js/jquery-ui.min.js?v=02e1058fd3cb0799867ba932a4ad3b22
I use this method of declaring static files:
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)
How can I get rid of 'v' variable in path?
Upvotes: 2
Views: 1386
Reputation: 1052
the v
is the static file hash that make by tornado according to content of file.
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.
the v
used for cache the file in client browser. you can imagine this is a part of file name.
if you don't want this, as tornado said, you can use nginx
server.
http://www.tornadoweb.org/en/branch2.3/overview.html#static-files-and-aggressive-file-caching
Upvotes: 2