Probably most of you have come across PageSpeed Insights by Google just like me. Using this tool I've analysed my website to see how it could be optimised. So far everything has been great up until now.
Google's tool indicated that I need to leverage browser caching by setting expiry date or max-age in HTTP header for static resources. During my research, I've across a number of guides how to do it: edgeguides.rubyonrails.org explained different ways of caching actions, templates, fragments of actions etc, but nothing about resources, big binary's guide led to crash in production and even though 'Rails 5 Revealed' e-book by Alan Bradburne did not give problem in development, no resources were served what so ever (TypeError: no implicit conversion of symbol hash key into String).
Problem shortly: how to configure config/environments/*.rb files so static resources would have 'Expire' and/or 'Max-age' in HTTP headers and satisty PageSpeed Insights? Here is the latest configuration I've used in config/environments/production.rb:
config.cache_store = :memory_store, { 64.megabytes }
config.public_file_server.enable = true
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800',
'Expires' => "#{1.month.from_now.to_formatted_s(:rfc822)}" }
Ruby on Rails version: 5.0.0.1