So I have a large amount of data, formatted as a JavaScript object, that my website needs access to. Because this data will not be updated, I have two options: create a JavaScript file and paste in the data as a variable. Or, I can upload the data as a JSON file, and then use an Ajax request to get the data and parse it into an object.
Here's some code to demonstrate what I mean.
Option 1 (save data as a JS object variable in a separate JS file):
File object.js
let myData = {
"1": "A",
"2": "B",
"3": "C",
"4": "D",
"5": "etc..."
};
...And so on, except my data is very large, so this file ends up being 25,000+ lines.
And I use the variable like this in some script.js
let myVar5 = myData["5"];
Option 2 (save data as JSON, do Ajax magic, and parse into JS object)
file object.json
{
"1": "A",
"2": "B",
"3": "C",
"4": "D",
"5": "etc..."
}
And then in my script.js I do this:
let url = "/data/object.json";
$.getJSON(url, function(response) {
let data = JSON.parse(response);
let myVar5 = data["5"]
}
Which option would have better performance, in terms of memory, speed, storage, and other practical stuff for websites on the internet?