这是对JavaScript加载时间更好:COM preSS都在一个大的文件或加载所有异步? [英] Which is better for JavaScript load-time: Compress all in one big file or load all asynchronously?

查看:120
本文介绍了这是对JavaScript加载时间更好:COM preSS都在一个大的文件或加载所有异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的问题,我不知道,如果它有一个简单的答案!

A simple question that I'm not sure if it has a short answer!

说明结果
我有JavaScript的一个文件来这里一个网站加载一些笔记关于他们:

Description
I have a files of JavaScript that to be loaded in a website here are some notes about them:


  • 他们都来自同一个域(不需要跨域加载)

  • 他们的网站周围的相同。

  • 有几个文件,如jQuery的,和其他5插件再加上我自己的应用程序脚本,是基于他们。

  • 它们的大小所有COM pressed = 224KB,(我的所有文件合并到一个文件然后我COM preSS他们一次使用YUI的COM pressor ​​2

问题结果
我听说224KB不理想是在一个文件!它应分成最大44KB的几个文件,当我听到这一点,我不知道它是否有效将其分割成多个文件,每个..我不记得,但它是真实的224KB需要很长时间加载首次,认为网站装入当然图像和CSS

Problem
I've heard that 224KB is not ideal to be in one file! and it should be split into several files with maximum of 44KB each .. I can't recall when I've heard this and I'm not sure if it's effective to split it into more files, but It's true that 224KB takes long time to load for the first time, consider that the website is loaded with images and css of course.

我已经最小化JavaScript文件的初装的需求,并把它放在底部,到目前为止,这是一个很好的进步,但我需要与HTML assynchounosly加载它争取时间的来源和decission使是:

I've minimized the need for the early loading of JavaScript file and put it on the bottom, so far this is a good progress but I need to load it assynchounosly with the HTML to gain time Source and the decission to make is:

是或否?结果
保持在一个COM pressed大文件?或者将它们分割成许多COM pressed文件并加载一个异步(我知道处理的依赖性有关的问题)?

Yes or No?
Keep it in one compressed big file? or to split them into many compressed file and loaded a asynchronously (I'm aware of handling the dependency related problems)?

推荐答案

这取决于什么该网站是如何重要的加载时间是它。

It depends on what the site is and how important first load time is for it.

不管,虽然,我可能会加载jQuery和类似的东西从公共CDN。一大好处是,即使他们从来没有到过你的网站就可能已经被缓存。

Regardless of that though, I'd probably load JQuery and stuff like that from a public CDN. One big benefit is that it might already be cached even if they have never been to your site.

<一个href=\"http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/\">http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/

卡布奇诺团队是一个文件的一大支持者 - 他们提出了一个JavaScript框架。与他们的工具开发的应用预计将有一定的加载时间。

The Cappuccino team is a big proponent of one file -- they make a javascript framework. Apps made with their tool are expected to have some load time.

<一个href=\"http://cappuccino.org/discuss/2009/11/11/just-one-file-with-cappuccino-0-8/\">http://cappuccino.org/discuss/2009/11/11/just-one-file-with-cappuccino-0-8/

这篇关于这是对JavaScript加载时间更好:COM preSS都在一个大的文件或加载所有异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆