These snippets demonstrate externalizing an application configuration for Javascript. This is useful to 1.) keep application configuration declarations out of your code so they can be easy changed throughout the application, and 2.) manage configuration across multiple environments where app configuration may be different for each target.
To implement:
- Create an identical app config JS file for each target (e.g. dev, test, prod)
- Modify the configuration variables in each config for each target
- Put each of these files in the same app_config folder at the root of your app, and add to SCM
- Add a script reference in your entry point (e.g. index.html) to the the app config file
- Modify the script reference to point to the correct version of your app config
The example below externalizes web service URLs for iron-ajax components in a Polymer app.
This could be improved, if you're using Maven or some other build tool, by creating a profile for each target that picks the correct version of the app-config file and deploys it to the correct location. That would save you from updating the script reference in step 5.