InstanceStatic should have reasonable caching

While here fix the naming convention of the old module attribute restricting caching and add a new one for the default cache value

All frontends should be shipped with versioned assets. There be dragons if you don't.
This commit is contained in:
Mark Felder 2022-07-01 15:40:40 -05:00
parent 75f912c63f
commit 6b74a55274

View file

@ -19,7 +19,8 @@ defmodule Pleroma.Web.Endpoint do
plug(Pleroma.Web.Plugs.HTTPSecurityPlug) plug(Pleroma.Web.Plugs.HTTPSecurityPlug)
plug(Pleroma.Web.Plugs.UploadedMedia) plug(Pleroma.Web.Plugs.UploadedMedia)
@static_cache_control "public, no-cache" @static_cache_control "public, max-age=1209600"
@static_cache_disabled "public, no-cache"
# InstanceStatic needs to be before Plug.Static to be able to override shipped-static files # InstanceStatic needs to be before Plug.Static to be able to override shipped-static files
# If you're adding new paths to `only:` you'll need to configure them in InstanceStatic as well # If you're adding new paths to `only:` you'll need to configure them in InstanceStatic as well
@ -30,22 +31,32 @@ defmodule Pleroma.Web.Endpoint do
from: :pleroma, from: :pleroma,
only: ["emoji", "images"], only: ["emoji", "images"],
gzip: true, gzip: true,
cache_control_for_etags: "public, max-age=1209600",
headers: %{
"cache-control" => "public, max-age=1209600"
}
)
plug(Pleroma.Web.Plugs.InstanceStatic,
at: "/",
gzip: true,
cache_control_for_etags: @static_cache_control, cache_control_for_etags: @static_cache_control,
headers: %{ headers: %{
"cache-control" => @static_cache_control "cache-control" => @static_cache_control
} }
) )
# Careful! No `only` restriction here, as we don't know what frontends contain. plug(Pleroma.Web.Plugs.InstanceStatic,
at: "/",
gzip: true,
cache_control_for_etags: @static_cache_disabled,
headers: %{
"cache-control" => @static_cache_disabled
}
)
plug(Pleroma.Web.Plugs.FrontendStatic,
at: "/",
frontend_type: :primary,
only: ["index.html"],
gzip: true,
cache_control_for_etags: @static_cache_disabled,
headers: %{
"cache-control" => @static_cache_disabled
}
)
plug(Pleroma.Web.Plugs.FrontendStatic, plug(Pleroma.Web.Plugs.FrontendStatic,
at: "/", at: "/",
frontend_type: :primary, frontend_type: :primary,
@ -62,9 +73,9 @@ defmodule Pleroma.Web.Endpoint do
at: "/pleroma/admin", at: "/pleroma/admin",
frontend_type: :admin, frontend_type: :admin,
gzip: true, gzip: true,
cache_control_for_etags: @static_cache_control, cache_control_for_etags: @static_cache_disabled,
headers: %{ headers: %{
"cache-control" => @static_cache_control "cache-control" => @static_cache_disabled
} }
) )
@ -79,9 +90,9 @@ defmodule Pleroma.Web.Endpoint do
only: Pleroma.Constants.static_only_files(), only: Pleroma.Constants.static_only_files(),
# credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
gzip: true, gzip: true,
cache_control_for_etags: @static_cache_control, cache_control_for_etags: @static_cache_disabled,
headers: %{ headers: %{
"cache-control" => @static_cache_control "cache-control" => @static_cache_disabled
} }
) )