Commit ·
cda9ef1
1
Parent(s): 41cae6d
Add Gzip compression to reduce network latency
Browse files- app.py +8 -1
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,12 +1,19 @@
|
|
| 1 |
from flask import Flask, send_from_directory
|
|
|
|
| 2 |
import os
|
| 3 |
|
| 4 |
app = Flask(__name__,
|
| 5 |
static_folder='static',
|
| 6 |
template_folder='.')
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
# Configuration optimisée pour production
|
| 9 |
-
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 31536000
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
@app.route('/')
|
| 12 |
def index():
|
|
|
|
| 1 |
from flask import Flask, send_from_directory
|
| 2 |
+
from flask_compress import Compress
|
| 3 |
import os
|
| 4 |
|
| 5 |
app = Flask(__name__,
|
| 6 |
static_folder='static',
|
| 7 |
template_folder='.')
|
| 8 |
|
| 9 |
+
# Activer la compression Gzip
|
| 10 |
+
Compress(app)
|
| 11 |
+
|
| 12 |
# Configuration optimisée pour production
|
| 13 |
+
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 31536000
|
| 14 |
+
app.config['COMPRESS_MIMETYPES'] = ['text/html', 'text/css', 'text/xml', 'application/json', 'application/javascript']
|
| 15 |
+
app.config['COMPRESS_LEVEL'] = 6
|
| 16 |
+
app.config['COMPRESS_MIN_SIZE'] = 500
|
| 17 |
|
| 18 |
@app.route('/')
|
| 19 |
def index():
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
Flask==3.0.0
|
| 2 |
gunicorn==21.2.0
|
|
|
|
|
|
| 1 |
Flask==3.0.0
|
| 2 |
gunicorn==21.2.0
|
| 3 |
+
flask-compress==1.15
|