Reputation: 6714
In my production.rb
I've set this:
# Enable serving of images, stylesheets, and JavaScripts from an asset server
config.action_controller.asset_host = "http://myassets.com"
And the images, js and stylesheets are loading fine from my CDN (assets server)
but what if someday this asset servers fails? and it returns a 404?
Because in my assets server (CDN) I have configure a pull zone
, the content is still available from /assets/..
.
Is there any fallback or how can I make a fallback so when my assets server
fails or return error my application loads assets from /assets/
inside the application?
Upvotes: 6
Views: 973
Reputation: 1709
production.rb
config.action_controller.asset_host = Proc.new { |source, request, asset_path|
if some_condition
"http://myassets.com"
else
asset_path
end
}
For more info, see AssetTagHelper
Edit
I don't think this precaution is worth the extra load/added requests to your application. If you were building a large application with failover servers to provide high availability, assets would be yet another thing you'd accommodate for with that redundancy. If you're hosting your stuff on the cloud through a service like AWS or Rackspace, I think you're good on availability and you shouldn't worry about the issue. This approach almost completely negates the benefit of caching assets.
Upvotes: 4
Reputation: 277
You might explore the following directive
ActionController::Base.asset_host = Proc.new { |source, request|
if #code to check if CDN is alive
"CDN Url"
else
"/public/assets/"
end
}
Upvotes: 0