简体   繁体   English

如何使用$ .ajax()或$ .post()更快地加载页面

[英]how can i load my page faster with $.ajax() or $.post()

i am trying to load database values from 6 - 7 tables on a single page ie users, their post eg with $.load(); 我试图在单个页面上从6-7个表加载数据库值,即用户,例如$ .load()的帖子; and it is taking from 15+ seconds to load but i want to load that page from 1-5 seconds ...i know it depends on internet connection speed but how can i do that .... 而且需要15+秒才能加载,但是我想从1-5秒加载该页面...我知道这取决于互联网的连接速度,但是我该怎么做....

You first have to identify the problem, and you've given us no information to do so. 您首先必须确定问题,并且没有给我们提供任何信息。

  1. It could be your webserver. 可能是您的网络服务器。 Check the latency through firebug -- this is pretty unlikely. 通过萤火虫检查延迟-这几乎是不可能的。
  2. It could be your queries. 可能是您的查询。 Test them and see how long they take to run. 测试它们,看看它们需要多长时间才能运行。
  3. It could be your script in general. 一般来说,它可能是您的脚本。 Test it and look for potential bottlenecks. 测试它并查找潜在的瓶颈。
  4. It could be the webpage itself - if the PHP runs fast (queries and script) and the data loads quickly (low latency, low delivery time) then it could be the method your using to insert the data into the page itself. 它可能是网页本身-如果PHP快速运行(查询和脚本)并且数据快速加载(低延迟,较低的交付时间),则可能是您用来将数据插入页面本身的方法。

You could postpone loading database information until after the page is loaded by requesting your data-centric components through Ajax but after adding everything up it'll probably be the same amount of time to fully load your page. 通过Ajax请求以数据为中心的组件,您可以将数据库信息的加载推迟到页面加载之后,但是在将所有内容累加起来之后,完全加载页面的时间可能相同。 Your problem is more along the lines of slow hardware, slow internet connection to/from your server. 您的问题更多是由于硬件速度较慢,与服务器之间的Internet连接速度较慢。 I'm guessing that you're on a shared host, which is probably why you're suffering from slower speeds. 我猜您在共享主机上,这可能就是为什么您速度较慢的原因。

How large are these tables? 这些桌子有多大? How much php script processing are you doing? 您正在执行多少PHP脚本处理? Have you looked at how long the queries take to run, outside of any script? 您是否在任何脚本之外查看了查询运行多长时间?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM