Configurable Cache-Control Headers in Marten for Environment-Specific Asset Management #220
Replies: 1 comment
-
Hey! 👋 The ability to set the max-age for the Cache-Control header is definitely something that should be added. I'll create an issue so that we don't forget to add this (edit - added in #221). Otherwise, yes - a PR adding this would be much appreciated! 🙏 😊 I'm interested to know, is there a particular reason why you're considering using this middleware in your development setup? I am asking because the Marten.routes.draw do
# Other routes...
if Marten.env.development?
path "#{Marten.settings.assets.url}<path:path>", Marten::Handlers::Defaults::Development::ServeAsset, name: "asset"
path "#{Marten.settings.media_files.url}<path:path>", Marten::Handlers::Defaults::Development::ServeMediaFile, name: "media_file"
end
end This is all that's needed to serve assets in development. 🙂 Ideally, the Marten.configure :production do |config|
config.middleware.unshift(Marten::Middleware::AssetServing)
end |
Beta Was this translation helpful? Give feedback.
-
Currently, if you use
Marten::Middleware::AssetServing
, this setting is always applied to the headersresponse.headers[:"Cache-Control"] = "private, max-age=3600"
. However, ideally, we should be able to set this value per environment.For example, for my development environment, I would like to
set config.assets.max_age = 0
to make the browser always request the latest file.I'm open to submitting a PR if you think this is a valid point.
Beta Was this translation helpful? Give feedback.
All reactions