Daniel Nill
Daniel Nill

Reputation: 5747

Injecting variables into cross domain scripts

I've written several javascript third-parties and browser extensions when I have the issue of wanting to change variable values between my local environment and my production environment.

In other languages I can simply create a file called settings or config or globals and import or include or require that file in the script I want to use the variables in, but frontend javascript doesn't seem to have namespacing or script inclusion. So I am wondering what can be done to easily change variable values on deploy.

An example of the issue I'm talking about:

say I have a script that is meant to be loaded by third parties:

(function(){
    var path = 'http://localhost:5000/some_script.js?callback=?&value=1';

    $.getJSON(path, function(data){
        console.log(data);
    });
})();

Because it is a third party script (it is meant to be loaded on domains other than the one it is hosted on) I can't use a partial but obviously I don't want path to be set to localhost:5000 in production.

What should I be doing?

Upvotes: 0

Views: 212

Answers (1)

Joseph
Joseph

Reputation: 119867

You should have a build step in your development process to convert these development values to production values using a build script.

Something like Apache Ant or something.

Upvotes: 1

Related Questions