使用php include或javascript ajax

时间:2022-11-05 20:32:46

I am creating a application and I am trying to figure out what the best approach is for me to load in json files.

我正在创建一个应用程序,我试图弄清楚加载json文件的最佳方法是什么。

One approach I am considering is php include

我正在考虑的一种方法是php include

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

or is Ajax better?

或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 would get loaded as of now, One of the files will grow over time and is unique per user, the second is a static file and the third is a large data file. The second and third file will be accessed by all users.

到目前为止,有3个json文件将被加载,其中一个文件会随着时间的推移而增长,每个用户都是唯一的,第二个是静态文件,第三个是大型数据文件。所有用户都将访问第二个和第三个文件。

What is the best way to maintain efficiency and good performance with high user growth over time? Should I be worried about anything specific with php or javascript ajax when there are 1000, 10000, or 1000000 users accessing one file simultaneously? Is there a different approach that should be taken?

随着时间的推移,高用户增长保持效率和良好性能的最佳方法是什么?当有1000,10000或1000000用户同时访问一个文件时,我应该担心php或javascript ajax的具体内容吗?是否应该采取不同的方法?

Thanks for all the tips/suggestions and different approaches.

感谢所有的提示/建议和不同的方法。

1 个解决方案

#1


4  

It depends on what you want it to act like. Each method is different. If you do an ajax call on $(document).ready, then the page will load first, then load the two files. If the files are massive then maybe you want to use AJAX, because then the whole page won't be slowed by that one call. If you want them there on pageload and only need them once, an include is fine. AJAX is only necesary when you want your calls to be asynchronous.

这取决于你想要它的行为。每种方法都不同。如果你在$(document).ready上进行ajax调用,那么页面将首先加载,然后加载这两个文件。如果文件很大,那么你可能想要使用AJAX,因为这样一个调用就不会减慢整个页面的速度。如果你想要它们在页面加载,只需要它们一次,包含就好了。当您希望调用是异步时,AJAX是必需的。

#1


4  

It depends on what you want it to act like. Each method is different. If you do an ajax call on $(document).ready, then the page will load first, then load the two files. If the files are massive then maybe you want to use AJAX, because then the whole page won't be slowed by that one call. If you want them there on pageload and only need them once, an include is fine. AJAX is only necesary when you want your calls to be asynchronous.

这取决于你想要它的行为。每种方法都不同。如果你在$(document).ready上进行ajax调用,那么页面将首先加载,然后加载这两个文件。如果文件很大,那么你可能想要使用AJAX,因为这样一个调用就不会减慢整个页面的速度。如果你想要它们在页面加载,只需要它们一次,包含就好了。当您希望调用是异步时,AJAX是必需的。