From 4d1c4f6348915aa084d54da64c5727c42c51735b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Fri, 27 Oct 2023 13:50:49 +0200 Subject: [PATCH] [FEAT] add cache busting via static_url_for and settings.cache_version (#1964) closes #1954 this PR add cache busting to `/static` additionally i combined `lnbits/core/static` with `lnbits/static`, it was not necessary and added a lot of duplicate code for cache busting. now you have to include all static files inside the html files with `{{ static_url_for("static", "app.css" ) }}` Co-authored-by: Vlad Stan Co-authored-by: Pavol Rusnak --- Makefile | 4 +- lnbits/app.py | 10 +-- lnbits/core/templates/admin/index.html | 2 +- lnbits/core/templates/core/index.html | 22 ++--- lnbits/core/templates/core/wallet.html | 2 +- lnbits/core/templates/node/index.html | 2 +- lnbits/core/templates/node/public.html | 2 +- lnbits/core/views/generic.py | 5 +- lnbits/helpers.py | 9 ++- lnbits/settings.py | 2 + lnbits/static/bundle.min.css | 2 +- lnbits/static/css/base.css | 6 -- lnbits/{core => }/static/extension.png | Bin lnbits/{core => }/static/favicon.ico | Bin lnbits/{core => }/static/js/index.js | 0 lnbits/{core => }/static/js/node.js | 0 lnbits/{core => }/static/js/service-worker.js | 2 +- lnbits/{core => }/static/js/wallet.js | 0 lnbits/static/scss/base.scss | 8 -- lnbits/static/vendor.json | 72 ++++++++--------- lnbits/templates/base.html | 17 +++- package.json | 76 +++++++++--------- 22 files changed, 122 insertions(+), 121 deletions(-) rename lnbits/{core => }/static/extension.png (100%) rename lnbits/{core => }/static/favicon.ico (100%) rename lnbits/{core => }/static/js/index.js (100%) rename lnbits/{core => }/static/js/node.js (100%) rename lnbits/{core => }/static/js/service-worker.js (99%) rename lnbits/{core => }/static/js/wallet.js (100%) diff --git a/Makefile b/Makefile index df5834d24..0bc340421 100644 --- a/Makefile +++ b/Makefile @@ -97,8 +97,8 @@ bundle: npm run vendor_bundle_js npm run vendor_minify_js # increment serviceworker version - sed -i -e "s/CACHE_VERSION =.*/CACHE_VERSION = $$(awk '/CACHE_VERSION =/ { print 1+$$4 }' lnbits/core/static/js/service-worker.js)/" \ - lnbits/core/static/js/service-worker.js + sed -i -e "s/CACHE_VERSION =.*/CACHE_VERSION = $$(awk '/CACHE_VERSION =/ { print 1+$$4 }' lnbits/static/js/service-worker.js)/" \ + lnbits/static/js/service-worker.js install-pre-commit-hook: @echo "Installing pre-commit hook to git" diff --git a/lnbits/app.py b/lnbits/app.py index 5438b2b3d..31ba46bf1 100644 --- a/lnbits/app.py +++ b/lnbits/app.py @@ -81,12 +81,10 @@ def create_app() -> FastAPI: setattr(core_app_extra, "register_new_ext_routes", register_new_ext_routes(app)) setattr(core_app_extra, "register_new_ratelimiter", register_new_ratelimiter(app)) - app.mount("/static", StaticFiles(packages=[("lnbits", "static")]), name="static") - app.mount( - "/core/static", - StaticFiles(packages=[("lnbits.core", "static")]), - name="core_static", - ) + # register static files + static_path = Path("lnbits", "static") + static = StaticFiles(directory=static_path) + app.mount("/static", static, name="static") g().base_url = f"http://{settings.host}:{settings.port}" diff --git a/lnbits/core/templates/admin/index.html b/lnbits/core/templates/admin/index.html index 3748d77e1..bec9dd615 100644 --- a/lnbits/core/templates/admin/index.html +++ b/lnbits/core/templates/admin/index.html @@ -164,5 +164,5 @@ {% endblock %} {% block scripts %} {{ window_vars(user) }} - + {% endblock %} diff --git a/lnbits/core/templates/core/index.html b/lnbits/core/templates/core/index.html index 985fd8652..1b370f624 100644 --- a/lnbits/core/templates/core/index.html +++ b/lnbits/core/templates/core/index.html @@ -1,5 +1,5 @@ {% extends "public.html" %} {% block scripts %} - + {% endblock %} {% block page %}
@@ -85,7 +85,7 @@
@@ -93,7 +93,7 @@
@@ -104,7 +104,7 @@ @@ -112,7 +112,7 @@ @@ -123,7 +123,7 @@ @@ -131,7 +131,7 @@ @@ -141,7 +141,7 @@ @@ -149,7 +149,7 @@ @@ -159,7 +159,7 @@ @@ -167,7 +167,7 @@ diff --git a/lnbits/core/templates/core/wallet.html b/lnbits/core/templates/core/wallet.html index 05f15f78a..d0062996a 100644 --- a/lnbits/core/templates/core/wallet.html +++ b/lnbits/core/templates/core/wallet.html @@ -3,7 +3,7 @@ {% from "macros.jinja" import window_vars with context %} {% block scripts %} {{ window_vars(user, wallet) }} - + {% endblock %} {% block title %} {{ wallet.name }} - {{ SITE_TITLE }} {% endblock %} diff --git a/lnbits/core/templates/node/index.html b/lnbits/core/templates/node/index.html index be6c71f04..3d1f4d7e1 100644 --- a/lnbits/core/templates/node/index.html +++ b/lnbits/core/templates/node/index.html @@ -42,7 +42,7 @@ {% endblock %} {% block scripts %} {{ window_vars(user) }} - + + + {% endfor %}