将 S3/CloudFront 与 Rails 3 资产和更少的 CSS 结合使用
这真是一口啊!基本上,我尝试将所有 Rails 3 资产发送到 S3 云,并使用 CloudFront 作为 CDN 来交付所有资产。我已经了解了如何将 Rails 配置为在生产模式下从资产服务器中提取。我遇到的问题是找到一种好方法来自动打包所有内容并将其从 rake 命令或 Rails gem 发送到云。我遇到的另一个问题是我不知道使用 Less CSS 和 More gem 是否会搞砸。 More 从另一个目录生成 CSS 文件并将其放置在 public/stylesheets 中。非常感谢任何想法或建议!谢谢 :)
This one is a mouthful! Basically I'm trying to send all of my Rails 3 assets up to the S3 Cloud and use CloudFront as the CDN to deliver it all. I already learned about configuring Rails to pull from an asset server in production mode. The problem I'm running into is finding a good way to automatically package and send everything to the cloud from a rake command or rails gem. The other problem I have is I don't know if using Less CSS with the More gem is going to screw this up. More generates a CSS file from another directory and places it in public/stylesheets. Any ideas or suggestions are much appreciated! Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您正在推送到 Heroku 并使用 Rails 3.1 资产,那么您就已经准备就绪。
在亚马逊的 CloudFront 配置中创建您的分配并将源设置为您的应用程序 URL。
然后在您的 production.rb 文件中添加:
主机是您的 CloudFront 发行版的主机。
然后,当您部署时,请确保您位于 Cedar 堆栈上并且正在编译资产。这将在文件名中添加唯一的 MD5。当向您的 CDN 发出请求时(由 Production.rb 文件中的设置自动处理),CDN 将提供其文件版本或首先从源中提取文件。这意味着您不必将文件推送到 CDN,它们会自动拉入。
如果您的文件由于某种原因没有唯一的名称,那么您将需要了解如何使 CloudFront 中的缓存失效,但除此之外,这非常简单。
If you are pushing to Heroku and are using the Rails 3.1 assets you are all set.
In the CloudFront configuration on amazon create your distribution and set the origin to your applications URL.
Then in your production.rb file add:
The host is the host of your CloudFront distribution.
Then when you deploy make sure you are on the Cedar stack and that assets are being compiled. This will add a unique MD5 into the filenames. When a request is made to your CDN (handled automatically by the setting in your production.rb file), then the CDN will either serve up it's version of the file or pull it from the origin first. This means you don't have to push files up to the CDN, they are pulled in automatically.
If you have a file that doesn't have a unique name for some reason, then you will need to look at how to invalidate the cache in CloudFront, but other than that it's pretty easy.