Context is a single page app with a rest backend.

For things like state and city lists, which rarely change, is it better to store them on server and load from client, or store them directly on client as javascript objects?

I am in favor of putting them on client to avoid writing boilerplate code (things like when state is selected city combo will be filled from server etc), but don't know if there's a downside.

  • 1
    There are 19,354 cities in the United States. You want to download that every time you load a page? – John Wu May 22 '18 at 3:35
  • This is a caching question. You need the server information but how long will you want to hang on to the result. – Thorbjørn Ravn Andersen Nov 18 '18 at 12:16

These two fields are related, so a dropdown list of cities would be filled dynamically based on the state. The structure for that would be easier to store in two database tables on the server side rather than reinventing the wheel on the client side. In addition, if you need to prefill the city and state based on a zip code, storing them on the server is better since you there's a many-to-many mapping required is much easier to maintain in a relational database.



I'd see it as a balancing act, and I'd orient it around user experience and hardware load, not code, you've got two choices;

  1. Load cities from server each time user clicks. [Fast first load, Laggy during use]
  2. Filter cities client-side. [Long first load, Fast during use]

You may also need to consider the computational expense of whatever you're doing, it may even run faster on a server...

Only you can answer this really;

  • User Experience Requirements
  • Hardware Load Requirements
  • Coding Expertise Requirements

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.