I’m writing a complex phonegap application. In this application some html files are downloaded from the web and put in device locale filesystem through phonegap file api http://docs.phonegap.com/en/2.2.0/cordova_file_file.md.html#File
I need to load those files on specific DOM parts and I started do it with ajax call to the resource. I tried also to read content file with FileReader api http://docs.phonegap.com/en/2.2.0/cordova_file_file.md.html#FileReader and load content directly in the related DOM part.
Either methods works well but I don’t know if there are some possible performance issue with one method rather than other.
Someone knows if is it faster (or better) using ajax call or access to file with FileReader and put content in the DOM?
The difference isn’t enough to matter, but the ajax call is probably slightly faster – it’s a single XHR, and on iOS the plugin call involves an XHR followed by encoding the file into a URL.
The real reason to favor the custom ajax call is that it will work when run on a desktop browser, which can be very useful for debugging.
The main benefit of the file reader plugin call is that it will work across all platforms, including some cases where the file may not normally be accessible to the browser.