Browse Source

Avoid custom stylesheet to be cached by third-party CDN

If the application is hosted behind a CDN like Cloudflare,
then all custom stylesheets is be the same for all users.

The random query string prevent the CDN to cache this.
Frédéric Guillot 4 years ago
parent
commit
1005fb973e
2 changed files with 5 additions and 1 deletions
  1. 4 0
      template/functions.go
  2. 1 1
      template/templates/common/layout.html

+ 4 - 0
template/functions.go

@@ -13,6 +13,7 @@ import (
 	"time"
 
 	"miniflux.app/config"
+	"miniflux.app/crypto"
 	"miniflux.app/http/route"
 	"miniflux.app/locale"
 	"miniflux.app/model"
@@ -87,6 +88,9 @@ func (f *funcMap) Map() template.FuncMap {
 				iconName,
 			))
 		},
+		"rand": func() string {
+			return crypto.GenerateRandomStringHex(10)
+		},
 
 		// These functions are overrode at runtime after the parsing.
 		"elapsed": func(timezone string, t time.Time) string {

+ 1 - 1
template/templates/common/layout.html

@@ -36,7 +36,7 @@
     <meta name="theme-color" content="{{ theme_color .theme }}">
     <link rel="stylesheet" type="text/css" href="{{ route "stylesheet" "name" .theme }}?{{ .theme_checksum }}">
     {{ if and .user .user.Stylesheet }}
-    <link rel="stylesheet" type="text/css" href="{{ route "stylesheet" "name" "custom_css" }}">
+    <link rel="stylesheet" type="text/css" href="{{ route "stylesheet" "name" "custom_css" }}?{{ rand }}">
     {{ end }}
 
     <script type="text/javascript" src="{{ route "javascript" "name" "app" }}?{{ .app_js_checksum }}" defer></script>