Webpacker: Leverage browser caching

Created on 1 Aug 2018  路  2Comments  路  Source: rails/webpacker

I ran a performance tool on my production environment and It says "Leverage browser caching for the following cacheable resources". It includes css, js, svg,...
based on your documentation it doesn't need any configuration for production. Is there a way to enable browser caching ?

Most helpful comment

This is more of a general Rails issue than webpacker related.

I'm assuming you're serving the assets with Rails. If so, you can control the cache headers by adding this to config/environments/production.rb:

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

All 2 comments

This is more of a general Rails issue than webpacker related.

I'm assuming you're serving the assets with Rails. If so, you can control the cache headers by adding this to config/environments/production.rb:

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

thanks @grk

Closing...

Was this page helpful?
0 / 5 - 0 ratings