April 12, 2012

whats faster, more efficient, loading a js file with arrays or populating arrays from tables

Question by Leigh

I am rebuilding an ecom site where the product data is stored in a multidimensional JS array that gets loaded on page load. This data is constantly being accessed with JS due to the nature of the site, to update prices based on user selections. There are many options that affect final price.

From a programming standpoint, a DB table is much easier to maintain and update than are JS arrays, and since I am porting the site over to PHP and MYSQL, I have been considering moving these arrays into tables.

So, would it be better to populate an array from the DB on load so that the pricing data is always available to the JS, or stay with hard coded JS files? I considered getting data via ajax as needed, but since this site has to constantly update pricing with user interaction, I have pretty much ruled that out.

How would you handle it?

Answer by Starx

No

I think its a bad idea to populate the database as array. If you do not filter the data you require from the database, this can be hazardous. Not to mention the amount of memory it is going to hog.

Sending correct ajax request, when a data is called for, is the right way to way.

Just look around Stackoverflow, the datas are very vital part, so all the necessary field are automatically updated when needed. It does not import all the db and store it on a array. It probably sends ajax request to check to see if something was updated.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!