I'm using Rails 4 and my app is deployed to Heroku.
我正在使用Rails 4,我的应用程序已部署到Heroku。
I'm trying to serve compressed assets from Cloudfront. Cloudfront's distribution origin points to Amazon S3, where the compressed version of js and css are present.
我正在尝试从Cloudfront提供压缩资产。 Cloudfront的分发源指向Amazon S3,其中存在js和css的压缩版本。
However, these compressed assets are not being served by Cloudfront. I've read that gems like heroku-deflater
and rack-zippy work
, but these will serve the assets from Heroku, as opposed to serving them from Cloudfront. In other words, I need my config.serve_static_assets
to be false
, as I want Heroku not to serve the assets.
但是,Cloudfront不提供这些压缩资产。我已经读过像heroku-deflater和rack-zippy这样的宝石,但是这些资源将来自Heroku,而不是从Cloudfront服务。换句话说,我需要将config.serve_static_assets设为false,因为我希望Heroku不要为资产提供服务。
How can I serve the compressed assets?
我如何提供压缩资产?
1 个解决方案
#1
Why not server them from Heroku? Hear me out:
为什么不从Heroku服务他们?听我说:
Create a Cloudfront Distribution that has the Heroku's app url as origin. Then just set config.asset_host = 'http://abcd12345678.cloudfront.net'
. This way Cloudfront gets hit, and if it doesn't have the compressed asset, it asks Heroku for it. Essentially, Heroku will server the assets only once (to CloudFront)
创建以Heroku的应用程序URL为原点的Cloudfront Distribution。然后只需设置config.asset_host ='http://abcd12345678.cloudfront.net'。这样Cloudfront就会受到攻击,如果它没有压缩资产,它会向Heroku询问它。从本质上讲,Heroku只会将资产服务一次(到CloudFront)
#1
Why not server them from Heroku? Hear me out:
为什么不从Heroku服务他们?听我说:
Create a Cloudfront Distribution that has the Heroku's app url as origin. Then just set config.asset_host = 'http://abcd12345678.cloudfront.net'
. This way Cloudfront gets hit, and if it doesn't have the compressed asset, it asks Heroku for it. Essentially, Heroku will server the assets only once (to CloudFront)
创建以Heroku的应用程序URL为原点的Cloudfront Distribution。然后只需设置config.asset_host ='http://abcd12345678.cloudfront.net'。这样Cloudfront就会受到攻击,如果它没有压缩资产,它会向Heroku询问它。从本质上讲,Heroku只会将资产服务一次(到CloudFront)