Does anyone use config files for javascript?

All you need to do is load a javascript file with some variable definitions, ideally namespaced. You can use a single object literal for this:

var config = {
  option1: 'goods', 
  option2: {name: 'option2'}, 
  option3: ['o','p','t','3']
}

Then load that file as your first script and you will have access to config information in each subsequent script eg

if (config.option1 == 'goods') doStuff();

Leave a Comment