0

My application needs static translation. I've entered the translations in a json file. I want to load this json file before the js files are loaded. How can I do it? Any help would be appreciated.

Nikhil
  • 665
  • 2
  • 11
  • 25

3 Answers3

1

Personally i would not rely on the order, the scripts are loaded in the document, but use a mechanism like the domready-event or even better something like require.js. With require.js you can load your JSON and after that do your JS-stuff.

domready-event: https://learn.jquery.com/using-jquery-core/document-ready/

require.js: requirejs load static JSON file

Community
  • 1
  • 1
Stefan Jelner
  • 111
  • 1
  • 4
0
$(function(){

  $.ajax({

      dataType: "json",

      url: 'path/to/json/file.json',

      success: function(result){

         // you can process the JSON result first
         // and call other functions after this point

      }

      });

  });
Diego Rafael Souza
  • 5,241
  • 3
  • 23
  • 62
nitinsridar
  • 684
  • 1
  • 12
  • 25
0

you can do something like this:

$(function(){
  $.ajax({
    dataType: "json",
    url: 'path/to/json/file.json',
    success: function(result){
        start(result)
    }
  });
});
function start(data /*converted to javascript object*/ ){
  // you can process the JSON result first
  // and call other functions after this point
}
behzad besharati
  • 5,873
  • 3
  • 18
  • 22