如何举办Rails的资产通过一个CDN不用按资产的Heroku资产、Rails、Heroku、CDN

2023-09-11 12:09:05 作者:年少德无知

所以,我现在有太多的资产,推到我的免费的Heroku账户。我目前的托管他们HostGator的服务器,它是有问题的,通过远程请求为每个图像上,而服务器本身不是的性质说,亚马逊的CloudFront的它加速和缓存的东西明确的CDN,这明显地加载所有所有图像慢就像在DOM。我的问题是,我怎么能起到通过CloudFront的我的资产没有他们推到我的Heroku的帐户?

So I currently have too many assets to push to my free heroku account. I am currently hosting them on a hostgator server which is problematic as, by making a remote request for each image, and the server itself not being of the nature of say Amazon CloudFront which expedites and caches things explicitly for CDN, it visibly loads all the images all slow-like in the DOM. My question is, how can I serve my assets through CloudFront without pushing them to my heroku account?

推荐答案

最好的解决方案是创建一个具有阶梯专门上传你的资产S3自定义部署脚本,然后通过CloudFront的服务从S3的资产。(有一起来看看 https://github.com/rumblelabs/asset_sync 的想法)

The best solution is to create a custom deployment script that has a step specifically for uploading your assets to S3, then serve the assets from S3 via CloudFront.(have a look at https://github.com/rumblelabs/asset_sync for ideas)

具体做法是:

您的资产添加到您的.gitignore 在production.rb文件中正确设置你的资产主机 第1步部署是拷贝改变资产,以你的S3存储在轨预计相同的文件夹结构 在部署第2步是你推式回购的标准命令混帐推Heroku的主 - 它不会把你的资产,只要它们正确地忽略 Add your assets to your .gitignore Set your asset host correctly in your production.rb file Step 1 in deploying is copy changed assets to your S3 bucket in the same folder structure that rails expects Step 2 in deploying is your push to repo with the standard command git push heroku master -- which will not push your assets if they are ignored correctly.