I'm working on the project that uses .json
file as a main source of data. Application is developed in Bootstrap, JavaScript/jQuery and HTML5. This code was developed few months ago and I'm trying to improve efficiency and update the code.
The first thing I noticed after reviewing the code was the way the data is included in this application. There are few .json
files that are used for different screens. These files are all over the place in different locations.
Also every time they do onclick
for example they reload the .json
file. There is no reason to do that since data is updated once a month. I'm wondering why this wouldn't be done only once (first time when application is loaded) and then set the data in js
object?
Is that a good practice or there is something better? Here is example on how I'm thinking to update this code:
var jsonData = {};
$(document).ready(function() {
$.getJSON('data.json', function(data){
// Load JSON data in JS object.
jsonData = data;
});
});
Should the code above be placed in html header
or body
tags? I know that nowadays .js
files are included on the bottom of body
tag and all .css
is in the header
. Is there any difference when comes to including json files? If anyone have any suggestions please let me know. The json files have around 600+ records with multiple fields (over 30). That might change in the future. So if these files get bigger I need to make sure that won't affect efficiency of the application overall.