Is it advisable to use arrays in Javascript using tens of thousands of indexes?

Is it advisable to use arrays in Javascript using tens of thousands of indexes?

I have a database which contains a table of static data, meaning that it will never change. In this case would it be advisable to convert this table to a javascript array and look the info up in there when needed? Is this bad practice?

The table in question contains roughly 40,000 key/value pair entries.

Answers


No.

I'd keep the table, as its a single point of maintenance.

You'll find that doing a XmlHTTPRequest to return a key/value pair based on a server side query, would actually perform faster, and have significantly less memory footprint than a huge JavaScript array.


In my experience, moving beyond a few thousand lines in an array cached client-side in a browser led to hellish experiences. Bloated browser memory footprints, slow load times and general sluggishness were the order of the day. You should test this scenario yourself for the experience. It's worth the few minutes it'd take you.


The main thing to take into consideration is end-user performance. Assuming that it works well on your machine will not mean it works well on an older machine. The riskiest part about the client-side aspect of your approach is that it depends heavily on what the client has. Personally, I would avoid putting that much data to the client, but I don't know enough of the background to your project to determine why you might need to do this.

Some sort of AJAX approach retrieving cached data from the server might be more appropriate.


Need Your Help

Get object from selected JTable

java swing jtable listselectionlistener

I have one JTable which show list of book and it can be filtered and sort

half open socket

c# sockets

In node.js, it is possible to have a half-open socket. This means that the socket can become read or write only without closing the whole socket. An example for this: