多个小文件V / S一个大文件HTTP请求 [英] Multiple small files v/s One big file for HTTP requests

查看:162
本文介绍了多个小文件V / S一个大文件HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道哪一个更好的办法,
拥有多个小型文件,由多个HTTP请求请求
要么
具有一次申请一个大文件

I was wondering which one is better approach, Having multiple small sized files to be requested by multiple HTTP requests OR Having a big file to be requested at once

PLZ提供赞成&安培;这两种方法的缺点也一样,我得到的净矛盾的搜索结果。

Plz provide pros & cons of both approaches too, as I get contradictory search results on net.

推荐答案

一个雅虎页面上的提示为尽量减少HTTP请求

One of the tips on Yahoo page is Minimize the HTTP Requests

http://developer.yahoo.com/performance/rules.html#num_http

主要的原因是,我们在每个请求一个额外的开销。雅虎说:

The main reason is that we have one extra overhead in each request. As yahoo says:

的最终用户响应时间的80%是花在前端。大多数
  这次在下载页面中所有的组件捆绑:
  图像,样式表,脚本,Flash等减少的数量
  反过来组件减少了所需的HTTP请求的数目
  渲染页面。这是关键更快的页面。

80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages.

在每次调用ASP.Net我们也有整个页面请求的会话锁定。这是什么意思是,所有用户的所有请求将不得不等待对方,因为会话是锁定页面的其余部分,直到当前页面完成。

Especial for ASP.Net

On every ASP.Net call we also have session lock of the entire page request. What this mean is that all requests for all users will have to wait for each other because the session is locking the rest of the page until the current page is finish.

即使这听起来很糟糕,它的开始和小网站有很大的帮助,因为它有很大帮助,对所有数据的同步,不仅与会话。

Even if that sounds bad, it is of great help for start and small sites because it helps a lot with the synchronization of all data, not only with the session.

所以多次调用你获得的数据序列,而不是平行的获取数据。

So with multiple calls you have a sequence of getting data, and not paralleled getting of data.

引用:<一href=\"http://stackoverflow.com/questions/9052401/jquery-ajax-calls-to-web-service-seem-to-be-synchronous\">jQuery Ajax调用到Web服务似乎是同步

<一个href=\"http://stackoverflow.com/questions/8989648/replacing-asp-nets-session-entirely/9021543\">Replacing ASP.Net会话完全

在每个请求还必须从浏览器传到服务器的cookies。所以,如果你的Cookie是近500个字节,你做100个电话,你有数据的额外50KB移动。这可以使用免费的饼干域​​来解决,但如果你没有这个选项,那么接下来的事情就是尽量减少通话。

On each request you also have cookies that travels from browser to server. So if your cookie is near 500 bytes and you make 100 calls you have an extra 50KB of data to move. This can be solved using a cookie-free domain, but if you do not have this option then the next thing is to try to reduce the calls.

参考: http://developer.yahoo.com/performance/rules.html# cookie_free

如果您有许多图像下载和浏览器上的显示,对包含精灵或其它图像一个文件图像,浏览器可以减少渲染时间,因为浏览器重新呈现每一个来自图像的每一个部分。但是,如果图像进来一个Sprite文件,然后在浏览器只需要一个动作,使它们 - 所以它是浏览器更快地拥有更少的文件

If you have many images to be downloaded and shown on the browser, against one file image that contains sprites, or other images, the browser can reduce the rendering time because the browser is re-rendering each part of every image that comes. But if the images come in one sprite file, then the browser take only one action to render them - so it's faster for the browser to have fewer files.

同样的事情放在这里。一旦你在一个或两个文件将所有您的JavaScript,然后在浏览器可以得到它,并在单次解析。如果你让他们尽可能多的文件,然后浏览器需要逐一分析它们。此外,如果您的gzip COM preSS JavaScript文件会比有许多小文件要好得多。

The same thing goes here. Once you combine all your javascript in one or two files then the browser can get it and parse them in a single time. If you have them as many files then the browser needs to parse them one by one. Additionally, if you gzip compress the javascript files it will be much better than having many smaller files.

有关我,你可以使用Ajax请求更多的数据时,这些数据可以来与用户交互。这可以是信息的要求提供备用数据库调用和计算,可以避开第一个请求,也许用户实际上从未要求他们。

For me you can use ajax to request for more data when this data can come with a user interaction. This can be informations that request extra database call and calculations that you can avoid on the first request, and maybe the user never actually asks for them.

您可以分割请求的方式,来获得额外的数据,只有当它的用户请求,如果你这样做这样就可以减少数据库调用。

You can split the requests that way, to get extra data only when the user requests for it, if you do it this way you will reduce database calls.

例如亚马逊的页面上的旋转木马控件加载额外的项目,只有当你在旋转木马要求更多的项目,或者只显示用户的历史,当你去了网页。

For example on Amazon's page the carousel control loads extra items only when you ask for more items in the carousel, or show the user history only when you go down the page.

这篇关于多个小文件V / S一个大文件HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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