Without Nginx, the flask data can be automatically gzip.
I used Flask to do a little thing myself, but the data in it is huge. Every time I get data from the server, I have to download more than 5 MB of data. I don't want to bother with the O & M shoes to change the configuration in Nginx, so I found the flask-compress.
How to use it? Easy
First download
1 |
pip install flask-compress |
Then, when the app is initialized
1 2 3 4 5 |
from flask import Flask from flask.ext.compress import Compress
app = Flask(__name__) Compress(app) |
Of course, it may not be possible only during initialization.
1 2 3 4 5 6 7 8 9 |
from flask import Flask from flask.ext.compress import Compress
compress = Compress()
def start_app(): app = Flask(__name__) compress.init_app(app) return app |
In practice, the results are infinitely good and no bugs have been found.
Of course, if the business volume is large, you should be honest with nginx.
This article permanently updates the link address: