--- title: Website load distribution using Javascript date: "2007-09-01T12:00:00Z" lastmod: "2009-02-25T08:57:09Z" categories: - coding wp_id: 75 --- My [music search engine](/hindi) shows a list of songs as you type -- sort of like Google's [autosuggest](http://www.google.nl/webhp?complete=1&hl=en) feature. I load my entire list of songs upfront for this to work. Though it's [compressed to load fast](/blog/hindi-songs-online/), each time you load the page, it downloads about 500KB worth of song titles. My allotted bandwidth on [my hosting service](http://www.100webspace.com) is 3GB per month. To ensure I don't exceed it, I uploaded the songs list to an alternate free server: [Freehostia](http://www.freehostia.com/). This keeps my load down. If I exceed Freehostia's limit, my main site won't be affected -- just the songs. I also uploaded half of them to [Google Pages](http://pages.google.com/), to be safe. This all worked fine... until recently. Google Pages has a relatively low bandwidth restriction. (Not sure what, and they won't reveal it, but my site is affected.) Freehostia is doing some maintenance, and their site goes down relatively often. So my song search goes down when any of these go down. Now, these are rarely down simultaneously. Just one or the other. But whenever Freehostia is down, I can't listen to one bunch of songs. When Google Pages is down, I can't listen to another. What I needed was a load distribution set-up. So I've made one in JavaScript. Normally, I load the song list using an external javascript. I have a line that says: ```html ``` ... and the song's loaded from Freehostia. What I'd like to do is: ```javascript loadscripts( "list.hasLoaded()", [ "http://sanand.freehostia.com/songs/...", "http://root.node.googlepages.com/...", "http://www.s-anand.net/songs/...", ], ); ``` If the function can't load it from the first link, it loads it from the second, and so on, until `list.hasLoaded()` returns true. Here's how I've implemented the function: ```javascript function loadscripts(check, libs) { document.write( "