2

I am building a JavaScript application where its behavior (some rules and logic) is configurable via JSON.

The configurations are deploy only with a new version of the app.

Currently my app, when initiated make few ajax requests to its JSON files.

I would like to know:

Should I include the configuration as a JavaScript module (so in a separate js file) and include it directly in the build, instead to have the app making and additional ajax requests? What is a common practice?

Thanks for your feedback.

1

This mainly depends on the complexity of your configuration. When using JSON, you cannot add comments (without tricks like "_comment": "...") to your configuration. When using JavaScript you have the ability to add values which are not available in JSON (like functions) but also the risk of having a program as configuration instead of a declarative file.

I personally would propose using YAML or TOML for your configuration and compile it to JSON as part of your build process. This will get you a declarative configuration file with comments without and runtime overhead.

| improve this answer | |

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.