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)?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With