简体   繁体   English

Amazon Cloudfront是否为后台主页图像或heroku提供服务? (rails app)

[英]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-urlasset-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.

相关问题 Heroku不提供背景图片,localhost呢? - Heroku does not serve background image, localhost does? 如何在Heroku上通过带有Rails的https通过Cloudfront资产提供服务? - How to serve cloudfront assets via https with rails on heroku? Heroku和Amazon CloudFront跨域资源共享和图像URL - Heroku and Amazon CloudFront Cross-Origin Resources Sharing and Image URL Rails 4 Heroku多租户应用重定向到heroku主页 - Rails 4 Heroku Multi-tenancy app redirecting to heroku homepage 背景图片Heroku Rails无法正常工作 - background image heroku rails not working 为什么Heroku上的Rails应用程序通过all.css和本地通过单个文件来提供资产 - Why does a rails app on heroku serve assets via all.css and locally via individual files 在 Heroku 上使用 Amazon S3 的 Rails 7 应用程序出现问题 - Problem with Rails 7 App with Amazon S3 on Heroku 服务.js和.css资产的问题Cloudfront CDN Heroku Rails 4 App - Problems serving .js and .css assets cloudfront CDN Heroku Rails 4 App Rails 4 App-Heroku / Cloudfront-资产无法从原始位置正确提供 - Rails 4 App - Heroku / Cloudfront - Assets not serving from origin properly Heroku Rails 4应用程序资产未通过AWS Cloudfront加载 - Heroku Rails 4 App Assets not loaded over AWS Cloudfront
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM