views:

82

answers:

3

im making a jquery autocomplete, i have something between 10~20k registers

the data is static (i'll run a update script when i need) and i can choose to get the file from a json or embed in the page in a single line, like:

var title = ["example title 1","example title 2"];

which one should i choose, perfomance wise? (also im worried about crashing/lagging peoples browser)..and how about XML?

btw my php script is already using a cache system for the html

A: 

Array is better choice with respect to performance. In spite of JSON is natural javascript format, still, objects instantiation from JSON is slower than creatng of array of strings. It is also smaller and you will experience network transmission.

Petr Kozelek
This is not true. JSON parsed with the `JSON.parse` method should theoretically be faster as the JS is not parsed with the normal JS tokenizer. Since JSON is a strict subset of ECMAScript, there are fewer possible tokens, thus making it a better choice than normal, embedded JS.
mattbasta
A: 

You should put the array in a separate .js file and load it via <script>. This lets the browser cache it separately from your HTML page (which will presumably change more frequently).

David Phillips
hm this look like a good idea
Checksummmmm
+1  A: 

You should consider using JSON over AJAX to fetch the data. It will make your page seem like it loads a lot faster. You can then use WebWorkers (if the system supports them) to parse the JSON data in a separate thread. This would be idea.

500kb of JSON likely would not cause any significantly significant parsing overhead, so I wouldn't worry about crashing anyone's browser.

mattbasta