0

I am creating a HTML/CSS + Javascript/Jquery project wherein a lot of configuration needs to be maintained. So, I was wondering what would be the best way to maintain a configuration file from which all the settings and stuff could be fetched.

I was planning to have a xml file as a configuration repository, but due to browser specific restrictions and blocks, I am perplexed as to what I should use for having a smooth progress.

Please suggest some. Thanks.

6
  • Not sure if this answers your question, but I got this answer stack overflow for my question about JavaScript configuration. Commented May 29, 2012 at 9:48
  • Exactly, I am not too keen on using XML. But does JSON have the same limitations as XML of not working properly on all browsers? Commented May 29, 2012 at 9:55
  • 1
    JSON is pure JavaScript so it works on all browsers. If you need to parse it from a string or serialize an object to a JSON string throw in github.com/douglascrockford/JSON-js/blob/master/json2.js to shim it for older browsers - but to use it in a .js file you don't need anything. It is pure JavaScript after all. Commented May 29, 2012 at 9:56
  • So, I create a myconfig.js file with all the configurations in json format and parse it using javascript/jquery? Does it work that way? Commented May 29, 2012 at 10:00
  • 1
    Yes, you simply have var config = {...}; and then use config.whatever in your application. Commented May 29, 2012 at 10:02

2 Answers 2

2

The most common way to configure JavaScript applications - both server-side and client-side - is using JSON.

On the server-side, YAML might be worth a thought, too, since many people consider it more readable and even easier to write.

Sign up to request clarification or add additional context in comments.

1 Comment

Is JSON free from the limitations of what XML has for different browsers?
0

I am working on an ASP.NET MVC3 project and was facing the same situation.

I used JSON. I read configuration from DB, created a Dictionary of Key Value pairs at the server side and then sent it to client side on an Ajax call (the JsonResult return type converts your DTO to JavaScript Object that is usable at the client side). There I placed it in a variable at the global level.

Now all my functions (that require configuration values) read that object to determine the course of their execution.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.