I just need some advice on if this is wise. I'm loading my site data largely through AJAX requests. To save load time and server calls I'm saving all data loaded to global objects and just recycling that data if the user selects the page again.
I wondered if it is wise to cache an entire site onto ONE object, e.g.:
var page = ['level 1','level 2','level 3','level 4'];
var mysiteobj = [];
if (page[0] == 'level 1')
if (!mysiteobj['level 1'])
$.ajax(/*load data*/).done(function(data){ mysiteobj['level 1'] = data; /*display data*/ });
else /*display mysiteobj['level 1']*/
if (page[1] == 'level 2')
if (!mysiteobj['level 1']['level 2'])
$.ajax(/*load data*/).done(function(data){ mysiteobj['level 1']['level 2'] = data; /*display data*/ });
else /*display mysiteobj['level 1']['level 2']*/
...etc
...and so forth. To clarify the rather odd notation, 'level 1' is all the geographic areas a user might look up, 'level 2' is all the departments in the geo the user might look it, 'level 3' would be the categories in the department in the geo, and say 'level 4' would be the product or entry listed in the category in the department in the geo.
Right now, my method is, I have an object with all the geographic areas, a second object is overwritten with a new department list every time a new geo loaded, and a third object holds my categories and fourth my listings/products.
If this makes sense, please advise. I guess the question simplified is, how large can you make an object before it becomes unwieldy and bogs down the browser?
Why not just load the data as needed, if not loaded already.
For example, you can load level 1.
Then, when the user selects level 2, load that if not already there, and continue.
So, you can keep what was already loaded, but just inform them that you are retrieving the data, if it takes time, otherwise people may understand that you are loading it.
Personally, I would show the user that there is a load request, so they know what is going on.
Preloading the entire site is a waste, IMO.
Considering that it's never wise make ajax requests returning large data sets....
I think you can storage this data into a Redis/Memcached server and make a javascript function that catch exactly what you want. It's not wise put that amount of data into a global variable and make your user pay for that.