Performance: Flask-Compress for compression
This affects the page load speed by reducing the size of HTTP responses sent from the server to the browser.
from flask import Flask from flask_compress import Compress app = Flask(__name__) compress = Compress() compress.init_app(app) @app.route('/') def index(): return 'Hello, world! This is a large response that could benefit from compression.'
from flask import Flask app = Flask(__name__) @app.route('/') def index(): return 'Hello, world! This is a large response that could benefit from compression.'
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No compression | N/A | N/A | Higher due to delayed content arrival | [X] Bad |
| Flask-Compress enabled | N/A | N/A | Lower due to faster content arrival | [OK] Good |
Flask-Compress in a Flask application?from flask import Flask
from flask_compress import Compress
app = Flask(__name__)
Compress(app)
@app.route('/')
def home():
return 'Hello, world!'app.config['COMPRESS_MIMETYPES'] = ['application/json'] before calling Compress(app) correctly sets COMPRESS_MIMETYPES to ['application/json'] before calling Compress(app). Call Compress(app, mime_types=['application/json']) after app creation is invalid because Compress does not accept mime_types parameter. Options A and D are incorrect configurations or decorators.Pass the test and this pattern moves unknown