diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 0c3c7737ea..4e82761e5d 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -152,7 +152,7 @@ module Rails end if config.serve_static_assets - middleware.use ::ActionDispatch::Static, paths["public"].first + middleware.use ::ActionDispatch::Static, paths["public"].first, config.static_cache_control end middleware.use ::Rack::Lock unless config.allow_concurrency diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index f818313955..29b9c27a13 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -9,7 +9,7 @@ module Rails :dependency_loading, :encoding, :filter_parameters, :force_ssl, :helpers_paths, :logger, :preload_frameworks, :reload_plugins, :secret_token, :serve_static_assets, - :session_options, :time_zone, :whiny_nils + :static_cache_control, :session_options, :time_zone, :whiny_nils attr_writer :log_level @@ -22,6 +22,7 @@ module Rails @helpers_paths = [] @dependency_loading = true @serve_static_assets = true + @static_cache_control = nil @force_ssl = false @session_store = :cookie_store @session_options = {} diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index d8d1e55157..8d11377211 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -7,7 +7,11 @@ # and recreated between test runs. Don't rely on the data there! config.cache_classes = true - # Log error messages when you accidentally call methods on nil. + # Configure static asset server for tests with Cache-Control for performance + config.serve_static_assets = true + config.static_cache_control = "public, max-age=3600" + + # Log error messages when you accidentally call methods on nil config.whiny_nils = true # Show full error reports and disable caching