Local script/css vs. CDN on mobile PhoneGap app

cdn, cordova, javascript

Solution

You are right. This is a common mistake for those who are new to PhoneGap which result in slow application start-up. Depend on the scenario, it may actually be a disbenefit to use CDN for mobile PhoneGap app. Due to webview/browser behavior, PhoneGap is picky on having all it's resources locally. If you want your application to load fast, all your initial resources should be local.

If you are a web developer, you've probably come across suggestion of loading JS file at the end of a body tag rather than in the head tag. The webview/browser thread availability is the same reason why it's better to have your file local in PhoneGap. Remember that you have to wait for body onload before PhoneGap deviceready event.

Now, on the other hand, if you load blogs/articles on subsequent Single Page Application view with ajax, then you will benefit from CDN hosting of your blog/article static contents.

Problem

I understand the benefits of including scripts and/or CSS through a CDN on a standard web page. However, it seems that in the case of a PhoneGap app in which all javascripts and CSS can be downloaded with the app, a CDN would actually decrease performance. So my question is: are there any benefits to using a CDN for a mobile PhoneGap app?

Original source