Add theme asset cache
- Use asset cache in Liquid head/foot tags - Set 30-day cache header for theme assets
This commit is contained in:
@@ -444,9 +444,11 @@ let updateTheme : HttpHandler = fun next ctx -> task {
|
||||
let themeName = themeFile.FileName.Split(".").[0].ToLowerInvariant().Replace (" ", "-")
|
||||
// TODO: add restriction for admin theme based on role
|
||||
if Regex.IsMatch (themeName, """^[a-z0-9\-]+$""") then
|
||||
let conn = ctx.Conn
|
||||
use stream = new MemoryStream ()
|
||||
do! themeFile.CopyToAsync stream
|
||||
do! loadThemeFromZip themeName stream true ctx.Conn
|
||||
do! loadThemeFromZip themeName stream true conn
|
||||
do! ThemeAssetCache.refreshTheme (ThemeId themeName) conn
|
||||
do! addMessage ctx { UserMessage.success with message = "Theme updated successfully" }
|
||||
return! redirectToGet (WebLog.relativeUrl ctx.WebLog (Permalink "admin/dashboard")) next ctx
|
||||
else
|
||||
|
||||
@@ -126,6 +126,10 @@ module Asset =
|
||||
let headers = ResponseHeaders ctx.Response.Headers
|
||||
headers.LastModified <- Some (DateTimeOffset asset.updatedOn) |> Option.toNullable
|
||||
headers.ContentType <- MediaTypeHeaderValue mimeType
|
||||
headers.CacheControl <-
|
||||
let hdr = CacheControlHeaderValue()
|
||||
hdr.MaxAge <- Some (TimeSpan.FromDays 30) |> Option.toNullable
|
||||
hdr
|
||||
return! setBody asset.data next ctx
|
||||
| None -> return! Error.notFound next ctx
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user