Use php include or javascript ajax

I am creating an application and I am trying to figure out what is the best way to download json files.

One approach I'm considering is php include

var jsonFile = <?php echo include "jsonFile.json";?>; var jsonFile_2 = <?php echo include "jsonFile2.json";?>; //and more possible includes 

or better is ajax?

 $.ajax({ type: "GET", url: "jsonFile.json", dataType: "json", success: function () { //more nested ajax calls } }); 

Or maybe a mixture of the two?

There are 3 json files that will be downloaded at the moment. One of the files will grow over time and is unique for each user, the second is a static file, and the third is a large data file. The second and third files will be available to all users.

What is the best way to maintain efficiency and good performance with high user growth over time? Do I have to worry about anything specific with php or javascript ajax when users 1000, 10000 or 1,000,000 access the same file at the same time? Is there any other approach that should be taken?

Thanks for all the tips / suggestions and different approaches.

+4
source share
1 answer

It depends on what you want it to act on. Each method is different. If you make ajax call in $ (document) .ready, then the page first loads, then two files load. If the files are massive, then perhaps you want to use AJAX, because then the whole page will not be slowed down by this single call. If you want them to be there in pageload and you need it only once, inclusive this is normal. AJAX is only needed when you want your calls to be asynchronous.

+4
source

Source: https://habr.com/ru/post/1490765/


All Articles