I have run a Lighthouse audit on my staging Rails 5 app (production on Heroku) and some warnings appeared regarding my static assets in the "Diagnostics" section.
All static assets on my splash page flag as "Uses inefficient cache policy on static assets" Though they appear properly and are properly fingerprinted.
Their CACHE TTL (Time to live) is set as "None" at the moment. (I am not even sure this is the actual problem..)
Is it possible to fix this easily ? Or maybe this is a setting on Heroku or my staging app to change ? Or maybe this is a normal behavior ...
How is your cache configured? (i.e. config.cache_store
?) Make sure that you have have a cache store like memcached or Redis set up. Outside of Heroku, one would use a web server like Nginx or Apache to serve static content. Here, unfortunately, the application server also needs to do that work.
To set the appropriate HTTP headers in current Rails versions, one should use config.public_file_server.headers
.
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=15552000',
'Expires' => 1.year.from_now.to_formatted_s(:rfc822)
}
In older versions of Rails, use config.static_cache_control
:
config.static_cache_control = 'public, max-age=15552000