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

Set Cache-Control headers for assets #401

Closed
wireframe opened this issue Feb 3, 2016 · 7 comments
Closed

Set Cache-Control headers for assets #401

wireframe opened this issue Feb 3, 2016 · 7 comments

Comments

@wireframe
Copy link
Contributor

Requests for ember assets are being proxied through the EmberCli::Deploy::File rack middleware, but does not set any of the HTTP cache control headers from rails.

Since ember production builds automatically digest the filenames of images/css/js/etc, these files are highly cachable, and should support the standard HTTP caching headers in some way (ex: rails static_cache_control config).

@wireframe
Copy link
Contributor Author

It may be possible/preferable to reuse the ActionDispatch::Static middleware which is what rails internals use to serve files from the public directory (and automatically sets the cache control headers).

@seanpdoyle
Copy link
Contributor

@wireframe that sounds like a great alternative!

Are you familiar enough with ActionDispatch::Static to create a PR?

@seanpdoyle
Copy link
Contributor

@wireframe I've thought about this further.

While we'd gladly accept a PR that implemented this functionality, it might not be necessary.

We encourage users to serve their assets over a CDN configured to pull from the Rails app.

This means that after the initial pull from origin, the Rails application would no longer serve the fingerprinted assets.

This limits the impact of Content headers (which are ultimately overwritten by the CDN) to a single request per asset.

@seanpdoyle
Copy link
Contributor

Closing this issue for now.

If you feel strongly about introducing ActionDispatch::Static, please open a PR and we can discuss further.

@wireframe
Copy link
Contributor Author

@seanpdoyle every CDN that i've worked with (cloudfront/fastly) acts as a reverse proxy to load resources from rails and then caches them on their edge servers. The duration of the cache relies 100% on the cache headers sent from the origin server (ie: rails) so the cache headers are extremely important in order to take full advantage of your CDN.

The thoughtbot blog you linked to actually explains this in detail. If rails isn't setting the "Cache-Control" header, your CDN will only cache that asset for a fairly short time and the benefit is very limited.

If you're CDN experience is different, I'd love to hear it, but this seems like a pretty standard flow for vanilla rails apps assets + CDN's.

@seanpdoyle
Copy link
Contributor

@wireframe thanks for clarifying, those are some good points.

I'll reopen this issue.

@seanpdoyle seanpdoyle reopened this Feb 4, 2016
seanpdoyle added a commit that referenced this issue Feb 5, 2016
Closes [#401].

Previously, requests for Ember assets were being proxied through
`EmberCli::Deploy::File` Rack middleware without the HTTP
`Cache-Control` header.

Ember `production` builds digest the filenames of images/css/js/etc.
This makes these files highly cachable.

This commit configures the underlying `Rack::File` middleware to serve
assets with the `Cache-Control` header set by Rails.

[#401]: #401
@seanpdoyle
Copy link
Contributor

@wireframe I've pushed #403. Please weigh in there.

seanpdoyle added a commit that referenced this issue Feb 5, 2016
Closes [#401].

Previously, requests for Ember assets were being proxied through
`EmberCli::Deploy::File` Rack middleware without the HTTP
`Cache-Control` header.

Ember `production` builds digest the filenames of images/css/js/etc.
This makes these files highly cachable.

This commit configures the underlying `Rack::File` middleware to serve
assets with the `Cache-Control` header set by Rails.

[#401]: #401
seanpdoyle added a commit that referenced this issue Feb 5, 2016
Closes [#401].

Previously, requests for Ember assets were being proxied through
`EmberCli::Deploy::File` Rack middleware without the HTTP
`Cache-Control` header.

Ember `production` builds digest the filenames of images/css/js/etc.
This makes these files highly cachable.

This commit configures the underlying `Rack::File` middleware to serve
assets with the `Cache-Control` header set by Rails.

[#401]: #401
seanpdoyle added a commit that referenced this issue Feb 5, 2016
Closes [#401].

Previously, requests for Ember assets were being proxied through
`EmberCli::Deploy::File` Rack middleware without the HTTP
`Cache-Control` header.

Ember `production` builds digest the filenames of images/css/js/etc.
This makes these files highly cachable.

This commit configures the underlying `Rack::File` middleware to serve
assets with the `Cache-Control` header set by Rails.

[#401]: #401
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

No branches or pull requests

2 participants