将数据加载到Web应用程序中

I've got a Web App that uses a data source encoded as JSON. I'm wondering if there's an advantage to loading the data as a variable from an external script using a standard tag vs. using the jQuery AJAX method to load the data.

If I'm loading the data as a variable from an external script it would look like this:

var settings = {"one" : 1, "two" : 2, "three" : 3};

I would load it using:

<script type="text/javascript" src="data.js"></script>

Then I can access it using:

console.log(settings.two);

If I'm loading the data via AJAX it would look like this:

{"one" : 1, "two" : 2, "three" : 3}

I would load it and access it using:

$.getJSON( 'data.json', function( settings ) {
  console.log(settings.two);
});

The biggest advantage I can see loading the data as an external script, would be that it loads before jQuery is ready and the "settings" variable can be accessed globally.

Any thoughts on which method to use?

Thanks, Howie

You should always load pure JSON data.

1) it saves you bandwidth

2) you are not bound to the variable name stored in the file(what if it conflicts with your variables?)

3) you may need to access your json data not only from javascript(you will get into a trouble if you put js code in the file)

4) don't mix data with code!