For maximum load speed and page efficiency, is it better to have:
- An 18MB JSON file, containing an array of dictionaries, that I can load and start using as a native JavaScript object (e.g.
var myname = jsonobj[1]['name']). - A 4MB CSV file, that I need to read using the jquery.csv plugin, and then use lookups to refer to:
var nameidx = titles.getPos('name'); var myname = jsonobj[1][nameidx]).
I’m not really expecting anyone to give me a definitive answer, but a general suspicion would be very useful. Or tips for how to measure – perhaps I can check the trade-off between load speed and efficiency using Developer Tools.
My suspicion is that any extra efficiency from using a native JavaScript object in (1) will be outweighed by the much smaller size of the CSV file, but I would like to know if others think the same.
What is your situation? Are you writing some intranet site where you know what browser users are using and have something like a reasonable expectation of bandwidth, or is this a public-facing site?
If you have control of what browsers people use, for example because they’re your employees, consider taking advantage of client-side caching. If you’re trying to convince people to use this data you should probably consider breaking the data up into chunks and serving it via XHR.
If you really need to serve it all at once then:
In other words: it depends. Benchmark it.