Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is there a RoR Gem / configuration that will serve assets locally if an external asset host name doesn't resolve or times out?


There 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


You 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"
  }


Not a gem, but from jQuery days:

<script> window.jQuery || document.write("<script src='js/jquery-1.10.2.min.js'>\x3C/script>")</script>


It'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."


Exactly, if a POP for Australia is down but works in Germany, better to serve this on the client side.


that'd be genius




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: