Minify html response
This commit is contained in:
15
app.py
15
app.py
@@ -7,6 +7,7 @@ from decorators import validate_person, validate_topset, validate_workout
|
|||||||
from db import DataBase
|
from db import DataBase
|
||||||
from utils import get_people_and_exercise_rep_maxes, convert_str_to_date, get_earliest_and_latest_workout_date, filter_workout_topsets, get_exercise_ids_from_workouts, first_and_last_visible_days_in_month
|
from utils import get_people_and_exercise_rep_maxes, convert_str_to_date, get_earliest_and_latest_workout_date, filter_workout_topsets, get_exercise_ids_from_workouts, first_and_last_visible_days_in_month
|
||||||
from flask_htmx import HTMX
|
from flask_htmx import HTMX
|
||||||
|
from htmlmin.main import minify
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_pyfile('config.py')
|
app.config.from_pyfile('config.py')
|
||||||
@@ -15,6 +16,20 @@ db = DataBase(app)
|
|||||||
htmx = HTMX(app)
|
htmx = HTMX(app)
|
||||||
|
|
||||||
|
|
||||||
|
@app.after_request
|
||||||
|
def response_minify(response):
|
||||||
|
"""
|
||||||
|
minify html response to decrease site traffic
|
||||||
|
"""
|
||||||
|
if response.content_type == u'text/html; charset=utf-8':
|
||||||
|
response.set_data(
|
||||||
|
minify(response.get_data(as_text=True))
|
||||||
|
)
|
||||||
|
|
||||||
|
return response
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
@ app.route("/")
|
@ app.route("/")
|
||||||
def dashboard():
|
def dashboard():
|
||||||
all_topsets = db.get_all_topsets()
|
all_topsets = db.get_all_topsets()
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ Jinja2==3.0.1
|
|||||||
jinja-partials==0.1.1
|
jinja-partials==0.1.1
|
||||||
psycopg2-binary==2.9.3
|
psycopg2-binary==2.9.3
|
||||||
flask-htmx==0.2.0
|
flask-htmx==0.2.0
|
||||||
python-dateutil==2.8.2
|
python-dateutil==2.8.2
|
||||||
|
htmlmin==0.1.12
|
||||||
Reference in New Issue
Block a user