Rails + Passenger on Heroku: set expiry date or a maximum age in the HTTP headers for static assets

64 views
Skip to first unread message

Amr Noman

unread,
Jan 14, 2016, 6:49:31 AM1/14/16
to Ruby on Rails: Talk

I'm using Rails api with an angularjs front-end which is served simply as static files under public directory (no sprockets or rails assets pipeline involved).

I've chosen passenger as the app server, deployed to heroku and everything seems to be working fine except for caching.

Since static assets are served directly by passenger/nginx, I'm thinking this has nothing to do with rails,  is this correct?

But I have no idea how to set cache headers or where to add configurations.


Response headers when requesting a static file (application-a24e9c3607.js):


Connection: keep-alive
Content-Length: 0
Date: Thu, 14 Jan 2016 06:45:31 GMT
Etag: "5696ce02-43102"
Last-Modified: Wed, 13 Jan 2016 22:21:54 GMT
Server: nginx/1.8.0
Via: 1.1 vegur

Any help appreciated. Thanks.

Frederick Cheung

unread,
Jan 14, 2016, 8:37:03 AM1/14/16
to Ruby on Rails: Talk


On Thursday, January 14, 2016 at 11:49:31 AM UTC, Amr Noman wrote:

I'm using Rails api with an angularjs front-end which is served simply as static files under public directory (no sprockets or rails assets pipeline involved).

I've chosen passenger as the app server, deployed to heroku and everything seems to be working fine except for caching.

Since static assets are served directly by passenger/nginx, I'm thinking this has nothing to do with rails,  is this correct?

But I have no idea how to set cache headers or where to add configurations.


That sounds correct. I don't know how one does this with nginx but with apache I configure apache to set an Expires / cache control header for anything in assets/. It looks like http://nginx.org/en/docs/http/ngx_http_headers_module.html is the relevant bits of the nginx docs.

Fred 

Amr Noman

unread,
Jan 14, 2016, 9:59:47 AM1/14/16
to Ruby on Rails: Talk
Thank you Frederick, I figured it out and answered my own question here.
Reply all
Reply to author
Forward
0 new messages