AJAX 加载时间 - 主机和服务器问题?

发布于 2024-09-27 13:07:17 字数 518 浏览 3 评论 0原文

我遇到 AJAX 调用缓慢的问题。这是一个常见问题,但我已经完成了我能找到的所有研究中建议的所有内容。我希望读过这篇文章的人能够达成共识。

基本上,我向 php 页面发出 ajax 请求,该页面从数据库获取信息。

这里是页面。

我已经对所有 javascript、mySQL 和 php 脚本、请求和页面进行了计时。 (如果你运行 firebug,你可以在控制台以及 xml 中看到我的时间标记)

作为示例 -

mysql 请求需要 20ms PHP页面耗时50ms ajax 成功脚本处理少量 xml(小于 1k)并生成标记,运行时间为 8 毫秒。

然而,加载页面需要近 4 秒的时间。

因此,假设我的脚本没有滞后,这一定是服务器响应时间或我自己的互联网连接的问题,对吧?

我很感激任何理论或想法。

谢谢

I'm having an issue with slow AJAX calls. This is a common question, but I've done everything suggested in all the research I can find. I'm hoping to get a consensus form people who read this.

Basically, I make an ajax request to a php page, which gets info from a database.

Here is the page.

I've timed all of my javascript, mySQL, and php scripts, requests, and pages.
(If you run firebug you can see my time markers in the console, as well as in the xml)

As an example -

The mysql request takes 20ms
The PHP page takes 50ms
The ajax success script, which processes the small amount of xml (less than 1k) and generates the markers, takes 8ms to run.

Yet, loading the page takes nearly 4 seconds.

So, assuming none of my scripts are lagging, this has to be a problem with the response time from the server, or my own internet connection, right?

I'd appreciate any theories or thoughts.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一影成城 2024-10-04 13:07:17

好的,查看了您的页面,以下是我看到的一些会影响速度的问题:

  1. 在 getMarkers 函数中获取数据需要 4 毫秒,但读取 xml 文件需要 892 毫秒。我建议您使用普通的 javascript 来读取您的 xml 文件,因为您执行的查找量确实会损害您的性能。
  2. 缩小并组合服务器本地的所有脚本。我得到了一些非常高的响应时间。通过执行此操作,您可以消除 4 个 http 请求,这对于服务器上的响应时间会有所帮助。 (注意不要在其中结合 jquery 或 jquery ui)
  3. 由于您的服务器有点慢(不是您的错,这会有所不同,因为您可能在共享托管上)我建议将 jquery 和 jquery ui 链接到 google cdn 托管版本。这是一篇关于 Jquery CDN
  4. 帖子您的页面上有 24 张图片;其中 23 个小于 4KB。将这 23 个组合成一个 CSS sprite 图像,并指定一个 1px X 1px 空白 gif 作为内联 html 图像,并改用 CSS sprite 图像。如果您不熟悉的话,这里有一篇关于这是什么的好文章: CSS Sprites 解释 这里也很好在线 css sprite 生成器:CSS Sprite 生成器
  5. 确保此页面需要 Jquery UI。我没有看到任何需要它的东西。如果你能删除它,你就可以节省 206k。如果不需要,请记住删除关联的 CSS 文件。这将为您节省另外 2 个电话。
  6. 没有深入挖掘,但如果您还没有开始调用在 $(document).ready() 中设置谷歌地图,这样页面的其余部分就可以加载,并且您可以在该区域显示加载动画。这样用户就知道正在发生一些事情,并且您的页面加载速度会更快。

因此,通过执行上述操作,您可以大大加快速度。您将从 82 个组件减少到 51 个本地组件,以及 Google CDN 上的 2 个组件。如果您可以改进 xml 读取时间,您还可以缩短近一秒的卸载时间

Ok looked at your page and here are some of the issues I saw that would affect speed:

  1. It takes 4ms to get your data in your getMarkers function but it takes 892ms to read the xml file. I would recommend falling back to vanilla javascript to read your xml file as the amount of find's you are performing is really harming your performance here.
  2. Minify and combine all of the scripts that are local on your server. I was getting some really high response times. You can eliminate 4 http requests by doing this which with the response times on your server will help a bit. (Note don't combine jquery or jquery ui in this)
  3. Since your server is a bit slow (not your fault this will vary as you are probably on shared hosting) I would recommend linking jquery and jquery ui to the google cdn hosted versions. Here is a post on that Jquery CDN
  4. You have 24 images on your page; 23 of which are under 4KB. Combine those 23 into one CSS sprite image and assign a 1px X 1px blank gif to be the inline html image and use the CSS sprite image instead. Here is good article on what this is if you are unfamiliar: CSS Sprites explained also here is good online css sprites generator: CSS Sprite generator
  5. Make sure you need Jquery UI for this page. I didn't see anything that would have required it. If you can remove it you save yourself 206k. Remember to remove the associated CSS file if it isn't needed. This would save you another 2 calls.
  6. Didn't dig too deep but if you are not already kick off the call to setup the google map in a $(document).ready() that way the rest of your page can load and you can display a loading animation in that area. This way users know something is happening and your page will appear to load a lot quicker.

So you can greatly speed things up by doing the above. You would go from 82 components down to 51 local and 2 more on Google CDN. If you can improve that xml read time you can shave nearly another second off load time as well

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文