I am writing an angular application, and I'm wondering how much client side memory to use.

I'm currently working on a scenario where there are 2 dropdowns. The second will load new values depending on the selection of the first. I'm thinking the max # of total records in the 2nd dropdown would be around 2000-3000 items, each being around 2k each. Each selection would display probably 10-15 items of the 2000-3000.

Should I load the entire array into memory and parse the selected values from there, or should I read from the server every time the first dropdown changes?

I know for a desktop this wouldn't be a big deal. But we support phones and tablets, and I'm not sure how much memory to worry about with these devices.

  • 2
    Each dropdown item is 2000 bytes? – Robert Harvey Jan 29 '15 at 16:12
  • 1
    Each model that is loaded is 2000 bytes. The model is used elsewhere, so I can't trim it down to just the Id and Value. The dropdown itself only uses 20 or so bytes of the 2000. – Scottie Jan 29 '15 at 16:13
  • "the 2nd dropdown would be around 2000-3000 items" why do you hate your users? – msw Jan 29 '15 at 16:38
  • 1
    @msw, I'm not displaying 2000-3000 at a time. There are a possible 2000-3000. The dropdown will only ever show 20-30 at a time, depending on the value of the first dropdown. – Scottie Jan 29 '15 at 16:39
  • "so I can't trim it down to just the Id and Value" - no chance to wrap the model or circumvent it and get only those two values for your dropdown? That would actually help. – Doc Brown Jan 29 '15 at 18:43

What you're describing is called a "cascading dropdown." It's commonly used by car websites to get Year, Make and Model.

I've seen a lot of these sites do an AJAX/JSON round trip for the sub-combos. There's a bit of a lag if you do this, unless it happens before the user opens the second dropdown. On a phone, I think you should probably do that instead of loading all of the items. Phone users are already used to things happening a bit more slowly.

In any case, make sure you can get the server to send only the 20 bytes per entry that you need for the dropdown. If you can't get it to do that, then taking the hit for all 2000 complete objects is probably out of the question (that's 4 megabytes, just for one page).

  • Is there any kind of a "suggested" limit to how much data to load per request? If it were, say, 25k, would that be acceptable? – Scottie Jan 29 '15 at 19:14
  • The only way to know for sure in your particular environment is to measure and test. – Robert Harvey Jan 29 '15 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.