3 ms·
Is there a RoR Gem / configuration that will serve assets locally if an external asset host name doesn't resolve or times out?
by cjreyes 12y ago
Is there a RoR Gem / configuration that will serve assets locally if an external asset host name doesn't resolve or times out?
- bbnnt 12y agothat'd be genius
- Hengjie 12y agoThere isn't, but there's a frontend library that you can use to add fallbacks to <script> tags: https://github.com/shinnn/script-fallback-from-urls https://github.com/shinnn/script-fallback-from-urls
- tbfrench 12y agoNot a gem, but from jQuery days: <script> window.jQuery || document.write("<script src='js/jquery-1.10.2.min.js'>\x3C/script>")</script>
- lukeschlather 12y agoIt's a decent idea, but it would be better to do client-side. For this sort of event, knowing that the name resolves on the server doesn't give you any confidence it will resolve for the client. What would be really nice is if you could specify a fallback host in your DNS prefetch, and the browser would make it "just work."
- thejosh 12y agoExactly, if a POP for Australia is down but works in Germany, better to serve this on the client side.
- jacobsenscott 12y agoYou can assign a proc to config.asset_host, so you could easily do it - config.asset_host = -> { cdn_up? ? "http://mycdn.com" : "http://mydomain.com" }