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.
Asked
Active
Viewed 276 times
0
-
1What did you tried ? – Anis D Mar 06 '17 at 14:11
-
@Nikhil Are you using any backend language? For example php. – Daniel Lagiň Mar 06 '17 at 14:13
-
Make sure to include the `json.js` file before the `functions.js`? – domsson Mar 06 '17 at 14:13
3 Answers
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