Search code examples
ruby-on-railsrubyruby-on-rails-5browser-cache

Rails 5 - Google Page Speed Insights - Leverage Browser Caching


I've got a Rails 5 development site running on a public server. The project is also in development mode. I have been scanning the site with Google Page Speed Insights and one of the largest suggestions has been to leverage browser caching. So, I looked around on google and every answer says to use this code:

config.public_file_server.headers = {
  'Cache-Control' => 'public, s-maxage=31536000, maxage=15552000',
  'Expires' => "#{1.year.from_now.to_formatted_s(:rfc822)}"
}

Because the project is in development mode I put this code in my development.rb file rather than production.rb. I haven't been able to get any different results by doing this. No errors either. I could use some guidance! Thanks in advance.


Solution

  • Testing a rails server in development is like trying to empty the oceans of water. The main changes in the production environment are performance enhancing configurations (caching, class reloading, asset compilation, etc).

    I'd suggest copying the default production configurations over to your development config if you want to test performance in development mode. This will probably make development painful for you, however.

    Or switch environments to production.

    What's your real goal here?