Avoid browser caching issues when assets changes

This commit is contained in:
Frédéric Guillot 2018-07-22 12:24:46 -07:00
parent 9f6533ece9
commit cfc1f3eb69
3 changed files with 13 additions and 8 deletions

View file

@ -107,10 +107,10 @@ var templateCommonMap = map[string]string{
{{ end }} {{ end }}
<meta name="theme-color" content="{{ theme_color .theme }}"> <meta name="theme-color" content="{{ theme_color .theme }}">
<link rel="stylesheet" type="text/css" href="{{ route "stylesheet" "name" .theme }}"> <link rel="stylesheet" type="text/css" href="{{ route "stylesheet" "name" .theme }}?{{ .theme_checksum }}">
<script type="text/javascript" src="{{ route "javascript" "name" "app" }}" defer></script> <script type="text/javascript" src="{{ route "javascript" "name" "app" }}?{{ .app_js_checksum }}" defer></script>
<script type="text/javascript" src="{{ route "javascript" "name" "sw" }}" defer id="service-worker-script"></script> <script type="text/javascript" src="{{ route "javascript" "name" "sw" }}?{{ .sw_js_checksum }}" defer id="service-worker-script"></script>
</head> </head>
<body data-entries-status-url="{{ route "updateEntriesStatus" }}"> <body data-entries-status-url="{{ route "updateEntriesStatus" }}">
{{ if .user }} {{ if .user }}
@ -239,6 +239,6 @@ var templateCommonMap = map[string]string{
var templateCommonMapChecksums = map[string]string{ var templateCommonMapChecksums = map[string]string{
"entry_pagination": "756ef122f3ebc73754b5fc4304bf05e59da0ab4af030b2509ff4c9b4a74096ce", "entry_pagination": "756ef122f3ebc73754b5fc4304bf05e59da0ab4af030b2509ff4c9b4a74096ce",
"item_meta": "2da78476f6c7fb8742c969ad1bfc20b7b61fddf97d79a77baf3cabda52f6fb49", "item_meta": "2da78476f6c7fb8742c969ad1bfc20b7b61fddf97d79a77baf3cabda52f6fb49",
"layout": "16658c13e91cab88ba4c49f14654a95b1db12054cc96def3e40360a52acc6c54", "layout": "952632cafa23e02e3ae74c33a6606e127ab7bff0b82a2aa848967da8966475a5",
"pagination": "b592d58ea9d6abf2dc0b158621404cbfaeea5413b1c8b8b9818725963096b196", "pagination": "b592d58ea9d6abf2dc0b158621404cbfaeea5413b1c8b8b9818725963096b196",
} }

View file

@ -33,10 +33,10 @@
{{ end }} {{ end }}
<meta name="theme-color" content="{{ theme_color .theme }}"> <meta name="theme-color" content="{{ theme_color .theme }}">
<link rel="stylesheet" type="text/css" href="{{ route "stylesheet" "name" .theme }}"> <link rel="stylesheet" type="text/css" href="{{ route "stylesheet" "name" .theme }}?{{ .theme_checksum }}">
<script type="text/javascript" src="{{ route "javascript" "name" "app" }}" defer></script> <script type="text/javascript" src="{{ route "javascript" "name" "app" }}?{{ .app_js_checksum }}" defer></script>
<script type="text/javascript" src="{{ route "javascript" "name" "sw" }}" defer id="service-worker-script"></script> <script type="text/javascript" src="{{ route "javascript" "name" "sw" }}?{{ .sw_js_checksum }}" defer id="service-worker-script"></script>
</head> </head>
<body data-entries-status-url="{{ route "updateEntriesStatus" }}"> <body data-entries-status-url="{{ route "updateEntriesStatus" }}">
{{ if .user }} {{ if .user }}

View file

@ -8,6 +8,7 @@ import (
"github.com/miniflux/miniflux/http/context" "github.com/miniflux/miniflux/http/context"
"github.com/miniflux/miniflux/template" "github.com/miniflux/miniflux/template"
"github.com/miniflux/miniflux/ui/session" "github.com/miniflux/miniflux/ui/session"
"github.com/miniflux/miniflux/ui/static"
) )
// View wraps template argument building. // View wraps template argument building.
@ -31,10 +32,14 @@ func (v *View) Render(template string) []byte {
// New returns a new view with default parameters. // New returns a new view with default parameters.
func New(tpl *template.Engine, ctx *context.Context, sess *session.Session) *View { func New(tpl *template.Engine, ctx *context.Context, sess *session.Session) *View {
b := &View{tpl, ctx, make(map[string]interface{})} b := &View{tpl, ctx, make(map[string]interface{})}
theme := ctx.UserTheme()
b.params["menu"] = "" b.params["menu"] = ""
b.params["csrf"] = ctx.CSRF() b.params["csrf"] = ctx.CSRF()
b.params["flashMessage"] = sess.FlashMessage() b.params["flashMessage"] = sess.FlashMessage()
b.params["flashErrorMessage"] = sess.FlashErrorMessage() b.params["flashErrorMessage"] = sess.FlashErrorMessage()
b.params["theme"] = ctx.UserTheme() b.params["theme"] = theme
b.params["theme_checksum"] = static.StylesheetsChecksums[theme]
b.params["app_js_checksum"] = static.JavascriptsChecksums["app"]
b.params["sw_js_checksum"] = static.JavascriptsChecksums["sw"]
return b return b
} }