Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone use config files for javascript?

We have javascript files that are environment specific, and so I was thinking of going down the path of creating a generic way to read in an XML (config) file to store different environment specific settings. I was curious to know if anybody else on here does that (or if not, is there a reason why you don't)?

like image 443
Justin Helgerson Avatar asked May 05 '10 18:05

Justin Helgerson


1 Answers

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(); 
like image 124
James Westgate Avatar answered Sep 28 '22 02:09

James Westgate