forked from cadence/breezewiki
		
	Try to add Link header to preload resources
This commit is contained in:
		
							parent
							
								
									ac17f40329
								
							
						
					
					
						commit
						cea9d2082b
					
				
					 2 changed files with 18 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -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])
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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))
 | 
			
		||||
     ", ")))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue