Configure Cache-Control for specific static resource in Rails

余生颓废 提交于 2020-03-26 03:52:07

问题


I am working on a Rails 4 app that requires serving some static assets under a defined URL. I have removed the digest from the resources as discussed in this thread: Serve compiled javascript and css files from rails app for use in external site

Of course this leaves me with the problem that browsers will cache the resources even though they may have been updated. Currently my file is served with the following HTTP Headers:

HTTP/1.1 200 OK
Server: nginx
Date: Thu, 23 Jan 2020 21:45:51 GMT
Content-Type: text/css
Content-Length: 166134
Last-Modified: Mon, 20 Jan 2020 00:03:46 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "5e24ee62-288f6"
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Cache-Control: public
Accept-Ranges: bytes

My understanding is, that I need to change Expires/Cache-Control to an appropriate value (like 8 hours) to make the browser eventually request another version of the resource.

How can I set up my rails config to set a specific cache policy for only these resources?

来源:https://stackoverflow.com/questions/59887924/configure-cache-control-for-specific-static-resource-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!