In my server, I retrieve an object from the database and have it in a variable as follows:
let files = [{"file1": "file1Data"}, {"file2": "file2Data"} ... ];
I want this data to be available in my client side JavaScript.
One way to do this would be to set up an API to call within my JavaScript. My thinking is that this would cause an extra round trip. This is because there is one request to load the initial HTML/JavaScript and then a further request to load the JSON data.
Therefore, it would be faster to send the JavaScript to the client along with the initial request that loaded the page.
How can I send a JSON object directly from the server and have it available in my client side JavaScript?