Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache-Control header not set in Rails 5 #39

Closed
rcrisp opened this issue May 19, 2017 · 10 comments
Closed

Cache-Control header not set in Rails 5 #39

rcrisp opened this issue May 19, 2017 · 10 comments

Comments

@rcrisp
Copy link

rcrisp commented May 19, 2017

I'm having trouble overwriting the Cache-Control header in my Rails 5 app. I have the following in my /config/environments/production.rb file:

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

This is applying to binary images fine (JPG/PNG/GIF) but JS and CSS assets still have the default max age of 86400 being applied (public, max-age=86400)

How am I able to update that? Is the configuration setting above not supposed to apply to those files as well?

I've tried specifying the gem using the GIT url directly as I noticed a fix for this recently. This did not change anything.

When I enable them gem in development I see max-age=31536000 set, however I don't seem to be able to update that either if I try a different value in development.rb and clear caches and restart servers.

@benoitongit
Copy link

I have the same issue with Rails 5.1

@brian-kephart
Copy link

There was a fix for this at the end of April, but a new release wasn't made. Are you two downloading the gem straight from this repository?

@romanbsd
Copy link
Owner

romanbsd commented Jun 8, 2017

If the git version fixes this issue, I'll go ahead and release an update.

@brian-kephart
Copy link

I think it's still not fixed. I thought it was, because the header is correct when I request a file with curl -I --compressed. However, loading that same file in Chrome gets me the incorrect header that people have reported.

I just tried the fork from PR #40 by @bookwitty and it has problems as well. The header is set as a hash. In other words, this line:
{ 'Cache-Control' => app.config.public_file_server.headers }

results in this header:
Cache-Control:{"Cache-Control"=>"public, max-age=31536000"}

@benoitongit
Copy link

15 days ago I tried from the repo and the released version but had no success. Cache control was always stuck to 24 hours.

@bmclean
Copy link

bmclean commented Jun 15, 2017

@benoitongit Try adding this in config/initializers/heroku_deflater_patch.rb:

module HerokuDeflater
  class CacheControlManager
    def cache_control_headers
      if rails_version_5?
        app.config.public_file_server.headers
      else
        app.config.static_cache_control
      end
    end
  end
end

dylanfisher added a commit to dylanfisher/heroku-deflater that referenced this issue Jul 9, 2017
romanbsd pushed a commit that referenced this issue Oct 16, 2017
* Cache-Control header not set in Rails 5

Fixes #39

* Simplify cache_control_headers and don't override other headers
@oleksandrkits
Copy link

@romanbsd can you please update it on Rubygems?

@justisb
Copy link

justisb commented Sep 26, 2019

Seems like this still never actually made it into a release?

@jmkristofzski
Copy link

Rubygems version hasn't been updated since January 2017 (version 0.6.3).

Use the following to use the github version:
gem 'heroku-deflater', git: 'https://github.com/romanbsd/heroku-deflater'

@romanbsd
Copy link
Owner

The issue is that commit f4d5b4c while fixing one thing, broke another, and also the specs are failing. I hadn't had time to look into it, and then forgot about it completely. If someone is willing to check, I'll be more than happy to receive a PR and release a new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants