[英]Does Amazon cloudfront serve the background homepage image or heroku? (rails app)
This is what I have inside production.rb (production environment) file. 这就是我在production.rb(生产环境)文件中的内容。
#Enable serving of images, stylesheets, and JavaScripts from an asset server
config.action_controller.asset_host = "xxxxxxxxxxxxx.cloudfront.net"
So it is enabled. 所以它已启用。 However, my background image stopped showing up when it used to work. 但是,我的背景图像在以前工作时停止显示。 Is it an error that I need to address on heroku or cloudfront? 我需要在heroku或cloudfront上解决这个错误吗? My background image size is 850kb. 我的背景图片大小为850kb。 Is it caused by the large image size? 是由大图像尺寸引起的吗?
In my css.scss file that point to the image, it is: 在我指向图像的css.scss文件中,它是:
.big {
width: 100%;
height: 450px;
position: absolute;
z-index: -999;
top: 41px;
left: 0;
background: url(../img/main.jpg);
}
So this is pointing to the /img folder in my heroku. 所以这指向我的heroku中的/ img文件夹。 Does this need to be changed to a file uploaded on Amazon S3? 是否需要将其更改为在Amazon S3上上传的文件? Why did my background image stop appearing? 为什么我的背景图片不再出现了? I am currently paying for an extra dyno on heroku if that makes any difference. 我目前正在为heroku支付额外的dyno,如果这有任何区别的话。
Thanks 谢谢
You need to use the image-url
or asset-path
helper that Rails gives you so that it writes out absolute image paths in your CSS files that are generated. 您需要使用Rails为您提供的image-url
或asset-path
帮助程序,以便在生成的CSS文件中写出绝对图像路径。 The assets are served directly from Cloudfront so the browser makes a request straight to cloudfront - none of it goes via Heroku except the stylesheet request. 资产直接从Cloudfront提供,因此浏览器直接向Cloudfront发出请求 - 除了样式表请求之外,它们都不通过Heroku。
You can read more about this at https://devcenter.heroku.com/articles/cdn-asset-host-rails31#asset-references-in-css-js 您可以在https://devcenter.heroku.com/articles/cdn-asset-host-rails31#asset-references-in-css-js上阅读更多相关信息。
This article also introduces the assetsync gem which is really handy here too. 本文还介绍了assetsync gem,它在这里也很方便。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.