Json vs big js array

im, creating jquery autocomplete, I have something between 10 ~ 20k registers

the data is static (I will run the update script when I need it), and I can choose to get the file from json or paste on the page on one line, for example:

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

Which one should I choose, skill? (also they were worried about the crashing / lagging people browser) .. and what about the XML?

btw my php script already uses caching system for html

+4
source share
3 answers

You must use JSON via AJAX to retrieve data. This will make your page look as if it loads a lot faster. Then you can use WebWorkers (if the system supports them) to parse JSON data in a separate stream. It will be an idea.

500kb JSON will probably not result in significant significant syntax overhead, so I would not worry about any browser crashing.

+2
source

You must put the array in a separate .js file and load it through <script> . This allows the browser to cache it separately from your HTML page (which is likely to change more often).

+2
source

Array is the best choice in terms of performance. Despite the fact that JSON is a natural javascript format, still instances of objects from JSON are slower than creating an array of strings. It is also smaller and you will experience network transmission.

+1
source

All Articles