diff --git a/.gitignore b/.gitignore index 8f04a1f..c0386f4 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ Dockerfile .env static/*.css static/*.css.map +static/*.min.js \ No newline at end of file diff --git a/app.py b/app.py index 2443b66..0d79cff 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,4 @@ +import re import threading import time @@ -5,7 +6,8 @@ from os import path, listdir from datetime import date from configparser import ConfigParser -import sass +from sass import compile as compile_sass +from htmlmin import minify as minify_html from flask import Flask, redirect, render_template, request, url_for, g, Response @@ -23,10 +25,20 @@ STATUS_FETCH_DELAY_SEC = 300 # 5 minutes app = Flask(__name__) if app.debug: - css = sass.compile(filename="static/style.scss") + # CSS Compilation and minification + css = compile_sass(filename="static/style.scss", output_style="compressed") with open("static/style.css", "w", encoding="utf-8") as f: f.write(css) + # JS minification + with open("static/script.js", encoding="utf-8") as f: + js = f.read() + js = re.sub(r"/\*.*?\*/", "", js, flags=re.S) + js = re.sub(r"//.*", "", js) + js = re.sub(r"\s+", " ", js).strip() + with open("static/script.min.js", "w", encoding="utf-8") as f: + f.write(js) + # ---------- LATEST COMMIT DATE (MINIMAL ADD-ON) ----------------------------- @@ -102,8 +114,6 @@ def _updater_loop(): _started = False _refresh_build_date_once() - -# Flask 3.x fix: start updater lazily on first request (since before_first_request is removed) _updater_lock = threading.Lock() @@ -172,9 +182,12 @@ def render_localized_template(lang, template_name): if lang not in locales_code: return redirect(url_for("index", lang=get_best_lang())) - return render_template( - template_name, - year=date.today().year, + return minify_html( + render_template( + template_name, + year=date.today().year, + ), + remove_empty_space=True, ) diff --git a/requirements.txt b/requirements.txt index c016db0..ff91176 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ blinker==1.9.0 click==8.1.8 colorama==0.4.6 Flask==3.1.0 +htmlmin==0.1.12 itsdangerous==2.2.0 Jinja2==3.1.6 libsass==0.23.0 diff --git a/static/style.scss b/static/style.scss index a6dc5d7..acb7c12 100644 --- a/static/style.scss +++ b/static/style.scss @@ -345,6 +345,12 @@ td { margin-left: 1em; } } + + &-info { + img { + margin-right: 0.25em; + } + } } hr { diff --git a/templates/download.html b/templates/download.html index 8c7c222..668b02f 100644 --- a/templates/download.html +++ b/templates/download.html @@ -78,7 +78,7 @@
| + |