From ac17f403294cfc6e8b1e5645cc6efabd5be2a752 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Fri, 11 Nov 2022 22:34:45 +1300 Subject: [PATCH 1/2] Fix font local definitions (?) --- static/main.css | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/static/main.css b/static/main.css index bed9cdb..0976e72 100644 --- a/static/main.css +++ b/static/main.css @@ -386,7 +386,7 @@ figcaption, .lightbox-caption, .thumbcaption { font-style: normal; font-weight: 400; font-display: swap; - src: local(""), + src: local("Source Sans Pro"), url("/static/source-sans-pro-v21-vietnamese_latin-ext_latin_greek-ext_greek_cyrillic-ext_cyrillic-regular.woff2") format("woff2"); } @font-face { @@ -394,22 +394,19 @@ figcaption, .lightbox-caption, .thumbcaption { font-style: italic; font-weight: 400; font-display: swap; - src: local(""), - url("/static/source-sans-pro-v21-vietnamese_latin-ext_latin_greek-ext_greek_cyrillic-ext_cyrillic-italic.woff2") format("woff2"); + src: url("/static/source-sans-pro-v21-vietnamese_latin-ext_latin_greek-ext_greek_cyrillic-ext_cyrillic-italic.woff2") format("woff2"); } @font-face { font-family: "Source Sans Pro"; font-style: normal; font-weight: 700; font-display: swap; - src: local(""), - url("/static/source-sans-pro-v21-vietnamese_latin-ext_latin_greek-ext_greek_cyrillic-ext_cyrillic-700.woff2") format("woff2"); + src: url("/static/source-sans-pro-v21-vietnamese_latin-ext_latin_greek-ext_greek_cyrillic-ext_cyrillic-700.woff2") format("woff2"); } @font-face { font-family: "Source Sans Pro"; font-style: italic; font-weight: 700; font-display: swap; - src: local(""), - url("/static/source-sans-pro-v21-vietnamese_latin-ext_latin_greek-ext_greek_cyrillic-ext_cyrillic-700italic.woff2") format("woff2"); + src: url("/static/source-sans-pro-v21-vietnamese_latin-ext_latin_greek-ext_greek_cyrillic-ext_cyrillic-700italic.woff2") format("woff2"); } From cea9d2082bc423f45c35e8c2037f0e1c73c399c0 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Fri, 11 Nov 2022 23:08:06 +1300 Subject: [PATCH 2/2] Try to add Link header to preload resources --- src/application-globals.rkt | 3 ++- src/static-data.rkt | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/application-globals.rkt b/src/application-globals.rkt index 595e9dd..a0ff8af 100644 --- a/src/application-globals.rkt +++ b/src/application-globals.rkt @@ -30,7 +30,8 @@ html-writing)) (define always-headers - (list (header #"Referrer-Policy" #"same-origin"))) ; header to not send referers to fandom + (list (header #"Referrer-Policy" #"same-origin") ; header to not send referers to fandom + (header #"Link" (string->bytes/latin-1 link-header)))) (define timeouts (easy:make-timeout-config #:lease 5 #:connect 5)) (define (application-footer source-url #:license [license-in #f]) diff --git a/src/static-data.rkt b/src/static-data.rkt index 9522639..c08c83a 100644 --- a/src/static-data.rkt +++ b/src/static-data.rkt @@ -1,14 +1,16 @@ #lang typed/racket/base (require racket/path - racket/runtime-path) + racket/runtime-path + racket/string) (provide - get-static-url) + get-static-url + link-header) (define-runtime-path path-static "../static") (define static-data - (for/hash ([f (directory-list path-static)]) : (Immutable-HashTable Path Nonnegative-Integer) + (for/hash : (Immutable-HashTable Path Nonnegative-Integer)([f (directory-list path-static)]) (define built (simple-form-path (build-path path-static f))) (values built (file-or-directory-modify-seconds built)))) @@ -18,3 +20,14 @@ path-or-filename (build-path path-static path-or-filename)))) (format "/static/~a?t=~a" (file-name-from-path the-path) (hash-ref static-data the-path))) + +(: link-header String) +(define link-header + (let* ([with-t '("main.css")] + [with-t-full (map get-static-url with-t)] + [without-t '("preact.js" "source-sans-pro-v21-vietnamese_latin-ext_latin_greek-ext_greek_cyrillic-ext_cyrillic-regular.woff2")] + [without-t-full (map (λ (path) (format "/static/~a" path)) without-t)]) + (string-join + (for/list : (Listof String) ([full-path : String (append with-t-full without-t-full)]) + (format "<~a>; rel=\"preload\"" full-path)) + ", ")))