更好地服务一个大js文件或几个小文件? [英] better to serve one big js file or several smaller ones?

查看:57
本文介绍了更好地服务一个大js文件或几个小文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如果我使用一个大的
javascript文件或将其分成几个较小的文件,我对服务器负载和下载时间感到好奇。哪个更好?

(首先下载脚本时请考虑这个因此

浏览器缓存是不合适的。)


谢谢,

彼得

解决方案

pe ********** @ gmail.com 在2006年3月22日上午1:45发表以下内容:< blockquote class =post_quotes>

如果我使用一个大的javascript文件或将其分成几个较小的文件,我对服务器负载和下载时间感到好奇。哪个更好?
(请将此视为第一次下载脚本,以便浏览器缓存不在等式中。)




这取决于你的目标。 IE将使用单独的文件加载它们

并使用单独的文件将允许浏览器继续并在下载时解析



-

兰迪

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /


2006年3月22日星期三01:52:42 -0500,Randy Webb

< Hi************@aol.com>写道:

pe ********** @ gmail.com在3/22/2006 1:45 AM说了以下内容:



如果我使用一个大的javascript文件或将其分成几个较小的文件,我对服务器负载和下载时间感到好奇。哪个更好?
(请将此视为第一次下载脚本,以便浏览器缓存不在等式中。)



这取决于在你的目标。 IE将使用单独的文件更快地加载它们并使用单独的文件将允许浏览器继续并在下载时解析它们。




假设连接良好,世界上许多地方没有良好的连接或使用高延迟移动连接(即使传输速度很高,也可以使用高延迟移动连接)提出请求的开销也很高,所以小文件需要很长时间才能被请求。


一个gzipped大文件是你最好的选择。


Jim。


Jim Ley写道:

[...] Randy Webb [...]写道:

pe ******** **@gmail.com 在2006年3月22日上午1:45发表以下内容:

如果我使用一个大的,我对服务器负载和下载时间感到好奇/> javascript文件或将其分成几个较小的文件。这是b etter?
(请在第一次下载脚本时将其视为这样,以便浏览器缓存不在等式中。)


这取决于您的目标。 IE将使用单独的文件加载它们更快并且使用单独的文件将允许浏览器继续并在下载时解析它们。


假设连接良好,很多世界没有良好的连接或使用高延迟的移动连接(即使传输速度很高,提出请求的开销也很高,如此之小文件需要很长时间才能被请求。

一个gzipped大文件是你最好的选择。




完全没有。


1.并非每个UA都支持gzip压缩的响应。那些不支持gzip压缩的响应。

将(希望)提供给那个大的未压缩版本

资源,有已知的缺点。如果一个人依赖gzip压缩,

不可避免地会比平常增加资源,如果gzip,

加载时间也会相当大

客户端不支持压缩。

2.理想情况下,每个资源应小于1160字节,以便轻松地将
合并到一个TCP / IP数据包中。因此,如果资源不是太大,那么这是一件好事。但是,必须在分配资源的块数和每个
块的大小之间找到一个健康的平衡,因为太多的块需要太多的HTTP请求。


3.功能应该分成多个图书馆,这些图书馆使用特定功能完全处理

。这样可以更容易地维护,如果只需要一个特定的功能来完成更小的下载大小,那么它可以避免人们出现问题

与较旧的编辑(有大小限制)。

PointedEars


Hi,

I''m curious about server load and download time if I use one big
javascript file or break it into several smaller ones. Which is better?
(Please think of this as the first time the scripts are downloaded so
that browser caching is out of the equation.)

Thanks,
Peter

解决方案

pe**********@gmail.com said the following on 3/22/2006 1:45 AM:

Hi,

I''m curious about server load and download time if I use one big
javascript file or break it into several smaller ones. Which is better?
(Please think of this as the first time the scripts are downloaded so
that browser caching is out of the equation.)



That depends on your aim. IE will load them faster using separate files
and using separate files will allow the browser to go ahead and parse
them as they are downloaded.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


On Wed, 22 Mar 2006 01:52:42 -0500, Randy Webb
<Hi************@aol.com> wrote:

pe**********@gmail.com said the following on 3/22/2006 1:45 AM:

Hi,

I''m curious about server load and download time if I use one big
javascript file or break it into several smaller ones. Which is better?
(Please think of this as the first time the scripts are downloaded so
that browser caching is out of the equation.)



That depends on your aim. IE will load them faster using separate files
and using separate files will allow the browser to go ahead and parse
them as they are downloaded.



Assuming a good connection, lots of the world doesn''t have a good
connection or are using high latency mobile connections (where even if
the transfer speeds are high the overhead of making a request is also
high, so small files take a long time to be requested.

one gzipped large file is your best bet.

Jim.


Jim Ley wrote:

[...] Randy Webb [...] wrote:

pe**********@gmail.com said the following on 3/22/2006 1:45 AM:

I''m curious about server load and download time if I use one big
javascript file or break it into several smaller ones. Which is better?
(Please think of this as the first time the scripts are downloaded so
that browser caching is out of the equation.)


That depends on your aim. IE will load them faster using separate files
and using separate files will allow the browser to go ahead and parse
them as they are downloaded.


Assuming a good connection, lots of the world doesn''t have a good
connection or are using high latency mobile connections (where even if
the transfer speeds are high the overhead of making a request is also
high, so small files take a long time to be requested.

one gzipped large file is your best bet.



Not at all.

1. Not every UA supports gzip-compressed responses. Those which do not,
will (hopefully) be served the uncompressed version of that large
resource, with the known drawbacks. If one relies on gzip compression,
inevitably the resources will grow larger than usual, and so will the
loading time considerably if gzip compression is not supported by the
client.

2. Ideally each resource should be less than 1160 bytes, to easily fit
into one TCP/IP packet. It is therefore a Good Thing if resources
are not too large. However, one has to find a healthy balance between
the number of chunks the resource is split into and the size of each
chunk, because too many chunks require too many HTTP requests.

3. Functionality should be splitted into libraries that deal exactly
with a particular feature. That allows for easier maintenance of,
usually overall smaller download size if only a particular feature
from that feature set is needed, and it avoids problems for people
with older editors (that have a size limit).
PointedEars


这篇关于更好地服务一个大js文件或几个小文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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