javascript 加载器什么时候比传统方法慢?

发布于 2024-11-30 01:08:41 字数 703 浏览 2 评论 0原文

我有一个包含大量资源的应用程序。在阅读了有关 javascript 加载器的内容后,我决定看看异步加载资源会带来什么样的提升。令我惊讶的是,我发现使用加载程序明显更慢(不需要秒表)。这让我想知道其他人是否有类似的结果,以及开发人员应该考虑何时使用或不使用 javascript 资源加载器。

以下是我的测试的一些详细信息:

  • 目前有 60 个资源(主要是脚本)
  • 由于依赖层次结构,脚本必须分大约 8 批加载
  • 主要使用 Firefox(但也在 Chrome 中尝试过)
  • 在 Ubunutu 和 Windows 上进行测试
  • 使用加载器 (在我的例子中是 YepNope)确实增加了一点开销
  • 我编写了一个小的引导加载程序类来简化我与 YepNope 的交互。
  • 源代码位于github上(运行tests.html和tests-loader.html)

当我说“慢一些”时,我并不是说它非常慢。只是我必须花一些时间来设置它,而且结果比我开始之前更糟糕。

60 个资源是否太少而无法使用加载器?资源通常应该很大还是可以是一堆小文件?哪些因素会导致加载器比使用传统脚本标签慢?

I have an app that has a bunch of resources. Having read about javascript loaders I decided to see what kind of boost I'd get from loading resources asynchronously. To my surprise I found that using a loader was visibly slower (no stopwatch needed). This has me wondering if others had similar results and what a dev ought consider regarding when to use or not use a javascript resource loader.

Here are some details about my tests:

  • Currently have 60 resources (primarily scripts)
  • Due to dependency hierarchies scripts had to be loaded in about 8 batches
  • Primarily used Firefox (but tried in Chrome as well)
  • Ran tests on both Ubunutu and Windows
  • Using a loader (YepNope in my case) does add a little overhead
  • I wrote a small bootloader class to simplify my interaction with YepNope.
  • Source code is on github (run tests.html and tests-loader.html)

When I say "slower" I'm not saying it's terribly slow. It's just that I had to spend some time to set this up and that the results were worse than before I started.

Is 60 resources too few to use a loader? Should resources generally be huge or can they be a bunch of small files? What kinds of things would cause a loader to be slower than using traditional script tags?

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

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

发布评论

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

评论(1

蓝天白云 2024-12-07 01:08:41

资源是异步加载的吗?首先,您使用的设备是多核的吗?异步。仅当您拥有多核计算机、笔记本电脑、平板电脑、手机或其他设备时,加载才有用。

第二,您使用的装载机质量好吗?尝试不同的加载器,据我所知,现在没有标准的“这很好”的加载器,所以你拥有的加载器可能会坏。另一种可能有效。

确定浏览器尚未优化页面资源加载吗?使用替代方法实际上可能会妨碍新的和更快的浏览器,从而减慢页面加载速度。

就我个人而言,我没有使用过这些加载程序,这些只是我的有根据的猜测。

Resources are loaded asynchronously? First of all, is the device you are using multi-core? Async. loading is only useful if you have a multi-core computer, laptop, tablet, phone, or other device.

Second, is the loader you use a quality one? Try different loaders, as I see it, there are no standard "this is good" loaders right now, so one you have might be broken. Another one may work.

Are you sure browsers aren't already optimizing page resource loading? Using an alternate way may actually get in the way of new and faster browsers, slowing down page loading.

Personally I haven't used these loaders, these are just my educated guesses.

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