From d3c5498d47869b3623b88dece68048d31867a2b8 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sun, 30 Oct 2022 23:51:15 +1300 Subject: [PATCH] "Cache-busting" for static files --- src/application-globals.rkt | 10 +++++----- src/niwa-data.rkt | 4 ++-- src/page-home.rkt | 7 ++++--- src/page-static.rkt | 4 +++- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/application-globals.rkt b/src/application-globals.rkt index 55dfddc..bbd5236 100644 --- a/src/application-globals.rkt +++ b/src/application-globals.rkt @@ -8,6 +8,7 @@ "config.rkt" "data.rkt" "niwa-data.rkt" + "static-data.rkt" "pure-utils.rkt" "xexpr-utils.rkt" "url-utils.rkt") @@ -37,7 +38,7 @@ `(footer (@ (class "custom-footer")) (div (@ (class ,(if source-url "custom-footer__cols" "internal-footer"))) (div (p - (img (@ (class "my-logo") (src "/static/breezewiki.svg")))) + (img (@ (class "my-logo") (src ,(get-static-url "breezewiki.svg"))))) (p (a (@ (href "https://gitdab.com/cadence/breezewiki")) ,(format "~a source code" (config-get 'application_name)))) @@ -127,14 +128,13 @@ ,@(map (λ (url) `(link (@ (rel "stylesheet") (type "text/css") (href ,url)))) (required-styles (format "https://~a.fandom.com" wikiname))) - (link (@ (rel "stylesheet") (type "text/css") (href "/static/main.css"))) + (link (@ (rel "stylesheet") (type "text/css") (href ,(get-static-url "main.css")))) (script "const BWData = " ,(jsexpr->string (hasheq 'wikiname wikiname 'strict_proxy (config-true? 'strict_proxy)))) ,(if (config-true? 'feature_search_suggestions) - '(script (@ (type "module") (src "/static/search-suggestions.js"))) - "")) - (body (@ (class ,body-class)) + `(script (@ (type "module") (src ,(get-static-url "search-suggestions.js")))) + "") (div (@ (class "main-container")) (div (@ (class "fandom-community-header__background tileHorizontally header"))) (div (@ (class "page")) diff --git a/src/niwa-data.rkt b/src/niwa-data.rkt index 24279d6..1b2d20c 100644 --- a/src/niwa-data.rkt +++ b/src/niwa-data.rkt @@ -49,7 +49,7 @@ "Icaruspedia" "https://www.kidicaruswiki.org/wiki/Main_Page" "/images/logos/icaruspedia.png" - "Icaruspedia is the Kid Icarus wiki that keeps flying to new heights. After going independent on January 8, 2012, Icaruspedia has worked to become the largest and most trusted independent source of Kid Icarus information. Just like Pit, they\"ll keep on fighting until the job is done.") + "Icaruspedia is the Kid Icarus wiki that keeps flying to new heights. After going independent on January 8, 2012, Icaruspedia has worked to become the largest and most trusted independent source of Kid Icarus information. Just like Pit, they'll keep on fighting until the job is done.") (("splatoon" "uk-splatoon" "splatoon3" "splatoon2") "Inkipedia" "https://splatoonwiki.org/wiki/Main_Page" @@ -145,7 +145,7 @@ "xexpr-utils.rkt") (define r (get "https://www.niwanetwork.org/members/")) (define x (html->xexp (bytes->string/utf-8 (response-body r)))) - (define english ((query-selector (λ (e a c) (println a) (equal? (get-attribute 'id a) "content1")) x))) + (define english ((query-selector (λ (e a c) (equal? (get-attribute 'id a) "content1")) x))) (define gen (query-selector (λ (e a c) (has-class? "member" a)) english)) (for/list ([item (in-producer gen #f)]) (define links (query-selector (λ (e a c) (eq? e 'a)) item)) diff --git a/src/page-home.rkt b/src/page-home.rkt index 9e7c954..0387fd3 100644 --- a/src/page-home.rkt +++ b/src/page-home.rkt @@ -4,6 +4,7 @@ html-writing web-server/http "application-globals.rkt" + "static-data.rkt" "url-utils.rkt" "xexpr-utils.rkt" "config.rkt") @@ -62,9 +63,9 @@ (head (meta (@ (name "viewport") (content "width=device-width, initial-scale=1"))) (title "About | BreezeWiki") - (link (@ (rel "stylesheet") (type "text/css") (href "/static/internal.css"))) - (link (@ (rel "stylesheet") (type "text/css") (href "/static/main.css"))) - (link (@ (rel "icon") (href "/static/breezewiki-icon.svg")))) + (link (@ (rel "stylesheet") (type "text/css") (href ,(get-static-url "internal.css")))) + (link (@ (rel "stylesheet") (type "text/css") (href ,(get-static-url "main.css")))) + (link (@ (rel "icon") (href ,(get-static-url "breezewiki-icon.svg"))))) (body (@ (class "skin-fandomdesktop theme-fandomdesktop-light internal")) (div (@ (class "main-container")) (div (@ (class "fandom-community-header__background tileBoth header"))) diff --git a/src/page-static.rkt b/src/page-static.rkt index 353a0f8..c9967ad 100644 --- a/src/page-static.rkt +++ b/src/page-static.rkt @@ -64,5 +64,7 @@ ((files:make #:url->path (lambda (u) ((make-url->path path-static) u)) #:path->mime-type (lambda (u) (ext->mime-type (path-get-extension u))) - #:cache-no-cache (config-true? 'debug) #;"browser applies heuristics if unset") + #:cache-no-cache (config-true? 'debug) + #:cache-immutable (not (config-true? 'debug)) + #:cache-max-age (if (config-true? 'debug) #f 604800)) conn new-req))