Search code examples
databaseweb-applicationsstatic-data

Where should I store static data in a web application


I have a general question about writing web applications. Many times I have static data, say a list of countries, or a list of options for radio buttons or a drop down menu. I don't like hard coding this stuff into the HTML because it makes it hard to change. I am wondering what is the best place to store the data. I've been storing it in tables in a database, but would rather not do this as I want to avoid slowing my application down by making unnecessary database calls. Should I just load it in the actual code file such as:

countries = ["America", "Canada", .... ]

or is there a better place?

Does it matter how much data it is? Would the answer change from a list of 5 items to a list of 500 or 5,000.


Solution

  • It depends on what you want.

    Hardcoding into the html is faster, and more efficient when your list is small. However, as your list grows longer, a database could be a better choice, because modifying the database is easier.

    An alternative option is to store the list in a separate file, and load it into your html using ajax, which is lighter than a database, and easier to modify than hardcoding.