Felipe Valdivia
Felipe Valdivia

Reputation: 369

CloudFront doesn't load my font-awesome rails 4

I have a problem with my rails app, I decided to move my assets to a CDN like cloudfront in AWS. Everything is better now. My assets are faster, but I have I problem: I'm using font-awesome gem for some icon in the app and since change to CloudFront they don't load.

My app is on heroku with CloudFront for assets. And my configuration in production env is:

# config/environments/production.rb
  config.action_controller.asset_host = "<YOUR DISTRIBUTION SUBDOMAIN>.cloudfront.net"

I hope a little help with that because I can't find the answer for that

Regards !

Upvotes: 3

Views: 4082

Answers (1)

Paddez
Paddez

Reputation: 908

If you're now loading a font from a different domain, most browsers will apply a Cross-Origin Resource Sharing limitation - that is to say, most browsers won't load a file from a different domain without a CORS Policy.

You can whitelist the font to be loaded by any-domain by first having your webserver that CloudFront is serving from, send the following response header:

Access-Control-Allow-Origin: "*"

Secondly, you need to go into your CloudFront configuration and whitelist the "Access-Control-Allow-Origin" header to be passed from your webserver, to the end-user.

More reading on CORS can be found here:

Upvotes: 8

Related Questions