From c2961bc2ca3ac3ed1d775550aad7b4bd727ffa85 Mon Sep 17 00:00:00 2001 From: trinkey Date: Fri, 20 Dec 2024 21:24:37 -0500 Subject: [PATCH] client caching --- tcommon/settings.py | 1 + tcommon/static/css/base.css | 18 +++++++++--------- tcommon/views/api.py | 2 ++ tcommon/views/static.py | 3 ++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tcommon/settings.py b/tcommon/settings.py index fda5e7e..4602367 100644 --- a/tcommon/settings.py +++ b/tcommon/settings.py @@ -5,6 +5,7 @@ from config import tCOMMON_TOKEN as SECRET_KEY # noqa: F401 BASE_DIR = Path(__file__).resolve().parent.parent +VERSION = (0, 0, 1) STATIC_DIR = BASE_DIR / "tcommon/static" ALLOWED_HOSTS = ["*"] diff --git a/tcommon/static/css/base.css b/tcommon/static/css/base.css index e199477..6dae8da 100644 --- a/tcommon/static/css/base.css +++ b/tcommon/static/css/base.css @@ -3,15 +3,15 @@ html { --rosewater: #f5e0dc; --flamingo: #f2cdcd; --pink: #f5c2e7; --mauve: #cba html[data-light] { --rosewater: #dc8a78; --flamingo: #dd7878; --pink: #ea76cb; --mauve: #8839ef; --red: #d20f39; --maroon: #e64553; --peach: #fe640b; --yellow: #df8e1d; --green: #40a02b; --teal: #179299; --sky: #04a5e5; --sapphire: #209fb5; --blue: #1e66f5; --lavender: #7287fd; --text: #4c4f69; --subtext1: #5c5f77; --subtext0: #6c6f85; --overlay2: #7c7f93; --overlay1: #8c8fa1; --overlay0: #9ca0b0; --surface2: #acb0be; --surface1: #bcc0cc; --surface0: #ccd0da; --base: #eff1f5; --mantle: #e6e9ef; --crust: #dce0e8; --base-low-op: #eff1f5b0} /* Font */ -@font-face { font-family: 'DejaVu Sans'; font-style: normal; font-weight: 400; font-display: block; src: url("/static/font/DejaVuSans.ttf") format("truetype"); } -@font-face { font-family: 'DejaVu Sans'; font-style: normal; font-weight: 700; font-display: block; src: url("/static/font/DejaVuSans-Bold.ttf") format("truetype"); } -@font-face { font-family: 'DejaVu Sans'; font-style: italic; font-weight: 400; font-display: block; src: url("/static/font/DejaVuSans-Oblique.ttf") format("truetype"); } -@font-face { font-family: 'DejaVu Sans'; font-style: italic; font-weight: 700; font-display: block; src: url("/static/font/DejaVuSans-BoldOblique.ttf") format("truetype"); } -@font-face { font-family: 'DejaVu Sans'; font-style: normal; font-weight: 200; font-display: block; src: url("/static/font/DejaVuSans-ExtraLight.ttf") format("truetype"); } -@font-face { font-family: "Ubuntu Mono"; font-style: normal; font-weight: 400; font-display: block; src: url("/static/font/UbuntuMono-Regular.ttf") format("truetype"); } -@font-face { font-family: "Ubuntu Mono"; font-style: italic; font-weight: 400; font-display: block; src: url("/static/font/UbuntuMono-Italic.ttf") format("truetype"); } -@font-face { font-family: "Ubuntu Mono"; font-style: normal; font-weight: 700; font-display: block; src: url("/static/font/UbuntuMono-Bold.ttf") format("truetype"); } -@font-face { font-family: "Ubuntu Mono"; font-style: italic; font-weight: 700; font-display: block; src: url("/static/font/UbuntuMono-BoldItalic.ttf") format("truetype"); } +@font-face { font-family: 'DejaVu Sans'; font-style: normal; font-weight: 400; font-display: swap; src: url("/static/font/DejaVuSans.ttf") format("truetype"); } +@font-face { font-family: 'DejaVu Sans'; font-style: normal; font-weight: 700; font-display: swap; src: url("/static/font/DejaVuSans-Bold.ttf") format("truetype"); } +@font-face { font-family: 'DejaVu Sans'; font-style: italic; font-weight: 400; font-display: swap; src: url("/static/font/DejaVuSans-Oblique.ttf") format("truetype"); } +@font-face { font-family: 'DejaVu Sans'; font-style: italic; font-weight: 700; font-display: swap; src: url("/static/font/DejaVuSans-BoldOblique.ttf") format("truetype"); } +@font-face { font-family: 'DejaVu Sans'; font-style: normal; font-weight: 200; font-display: swap; src: url("/static/font/DejaVuSans-ExtraLight.ttf") format("truetype"); } +@font-face { font-family: "Ubuntu Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("/static/font/UbuntuMono-Regular.ttf") format("truetype"); } +@font-face { font-family: "Ubuntu Mono"; font-style: italic; font-weight: 400; font-display: swap; src: url("/static/font/UbuntuMono-Italic.ttf") format("truetype"); } +@font-face { font-family: "Ubuntu Mono"; font-style: normal; font-weight: 700; font-display: swap; src: url("/static/font/UbuntuMono-Bold.ttf") format("truetype"); } +@font-face { font-family: "Ubuntu Mono"; font-style: italic; font-weight: 700; font-display: swap; src: url("/static/font/UbuntuMono-BoldItalic.ttf") format("truetype"); } body { margin: 0; diff --git a/tcommon/views/api.py b/tcommon/views/api.py index 4aa19dd..aaf043c 100644 --- a/tcommon/views/api.py +++ b/tcommon/views/api.py @@ -5,6 +5,7 @@ from django.http import HttpResponse from config import (DEBUG, ENABLED_APPLICATIONS, tCOMMON_TOKEN, tCOMMON_URL_INTERNAL, tCOMMON_URL_PUBLIC) +from tcommon.settings import VERSION def initialize(request: WSGIRequest) -> HttpResponse: @@ -19,6 +20,7 @@ def initialize(request: WSGIRequest) -> HttpResponse: resp = { "debug": DEBUG, + "version": list(VERSION), "success": True, "services": { "common": { diff --git a/tcommon/views/static.py b/tcommon/views/static.py index 90e1fbe..05da5f7 100644 --- a/tcommon/views/static.py +++ b/tcommon/views/static.py @@ -1,5 +1,6 @@ from django.http import HttpResponse from django.urls import path +from django.views.decorators.cache import cache_page from tcommon.settings import STATIC_DIR @@ -20,7 +21,7 @@ file_associations = { "ttf": "font/ttf" } -urlpatterns = [path(i, get_static_serve(i, file_associations[i.split(".")[-1]])) for i in [ +urlpatterns = [path(i, cache_page(60 * 60 * 24 * 30)(get_static_serve(i, file_associations[i.split(".")[-1]]))) for i in [ "css/base.css", "js/theme.js", "font/DejaVuSans-Bold.ttf",