Increasing `loadUrlTimeoutValue` to avoid `Connection to server was unsuccessful` error

If your PhoneGap application loads some external content (either local files or any server-side data) using AJAX, keep an eye on the fact, that on very slow mobile devices, it may end up with error message saying, that connection to given URL failed. Which means a typical timeout.

You may experience the very same issue, if you’re building apps in debug mode and debug server (either yours or default weinre one) is down or responds to slowly.

Both problems can be solved by setting project preference called loadUrlTimeoutValue to some high value. How big? It depends. Some says, that default value is 2000, which means only two seconds. I found it way to slow for XHR local files loading or accessing weinre debug server on slow mobile devices.

Some people say that setting this to 60000 (60 seconds) is quite enough for any mobile device. But in the very same time others claims that even this can be to slow for some emulators (and — assuming — debug servers) and propose to set timeout to… 360000, that is 360 seconds, that is six minutes. Wow! That’s bit mad! :]

Some other claims, that increasing this value won’t bring permanent solution and offers alternative. I don’t find this alternative solution too nice, but see for yourself.

BTW: Keep in mind, that when compiling in the cloud (via PhoneGap Build), you have to use hyphen notation (load-url-timeout) and that is how it is documented in config.xml documentation. While, when building PhoneGap apps locally, you have to use camel case notation (loadUrlTimeoutValue). And that’s, how it is presented in Project Settings for Android in PhoneGap configuration documentation.

Leave a Reply