Use xhr to check if api exists on localhost. If yes, use that instead.

Ref: http://www.kirupa.com/html5/check_if_internet_connection_exists_in_javascript.htm