DataTables AJAX Performance: Data Takes Too Long to Load

I’m using the DataTables library in the back office of my website to display dynamic tables of data. While everything is working correctly, the data loading time is excessively long. I’m using the AJAX option to retrieve the data, but it takes at least 5 seconds to display.

var table = $('#myTable').DataTable({
  ajax: '../../api/adminConsulter.php'
});

Analyzing the browser console, I found that loading libraries takes about 1.3 seconds, while the actual data loading takes 5.11 seconds. Intriguingly, the script that sends data in JSON format loads in milliseconds when opened directly (without AJAX request) and I don’t have that much to load (around 500 rows which represent 480kb).

I’ve examined the browser console to identify bottlenecks. Loading libraries takes time, but it’s not the sole issue.

I observed that the script sending data in JSON is fast when opened directly, ruling out script-related problems.

Any suggestions on how to improve the data loading time with DataTables using the AJAX option?