You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in order to reduce the size of static resources,i use webpack to compress the static file, for example, compressing "chunk-vendors.665e9203.js" like this:‘’chunk-vendors.665e9203.js.gz‘’. but i do not know how to set the tornado to return the gz file in the hope?
The text was updated successfully, but these errors were encountered:
This kind of works, but not exactly how you're expecting. If you upload foo.js.gz, Tornado will serve that compressed file at /static/foo.js.gz as an application/x-gzip content-type. That's not going to work for most browser assets. Instead, you need to send the file with content-type text/javascript and content-encodinggzip. StaticFileHandler can't do this for files that are compressed on disk, although it would be a nice feature to add.
Instead, if you put the file on disk uncompressed and pass compress_response=True to your Application constructor, Tornado will transparently compress the file and serve it up with the correct encoding to reduce the data transferred (but it will recompress the file every time it's requested, so it's not ideal for cpu usage).
You can also consider serving your static files from somewhere other than Tornado. Tornado is a relatively expensive way to serve static files so pairing it with e.g. nginx for production environments is a good solution, described in the user's guide
bdarnell
changed the title
How to upload compressed static files
Serve pre-compressed files with StaticFileHandler
Nov 29, 2020
in order to reduce the size of static resources,i use webpack to compress the static file, for example, compressing "chunk-vendors.665e9203.js" like this:‘’chunk-vendors.665e9203.js.gz‘’. but i do not know how to set the tornado to return the gz file in the hope?
The text was updated successfully, but these errors were encountered: