简体   繁体   English

网站页面加载时间和保持活动状态的http连接

[英]Website page load time and keep-alive http connections

Background: I prefer to keep all my CSS and Javascript in separate .css/.js files. 背景:我更喜欢将所有CSS和Javascript放在单独的.css / .js文件中。 (Reason is that they are shared by many pages so in this way, static data in those file would not get transferred with each page view). (原因是它们被许多页面共享,因此,这种文件中的静态数据不会在每个页面视图中传输)。 This leads to some pages having 5-6 "link rel" or "script type" statements. 这导致某些页面具有5-6个“链接相关”或“脚本类型”语句。

Now, normally, this would mean that browser would make separate request for each of those css/js files, and effective page load time can increase - say become 5X for 5 round trip requests (please correct me if I am wrong here). 现在,通常,这意味着浏览器将对每个css / js文件分别发出请求,并且有效页面加载时间会增加-例如,对于5次往返请求,其变为5倍(如果我错了,请纠正我)。

My question is: 我的问题是:

1) Do modern browsers request keep-alive connections by default? 1)默认情况下,现代浏览器是否要求保持连接?

2) If they do, then does it mean that additional file sourcing (css/js) will not increase the effective load time? 2)如果这样做,是否意味着额外的文件源(css / js)不会增加有效的加载时间? For example - will the server assume that browser is going to request the css/js files, and hence keep sending it (thus avoiding an extra request)? 例如-服务器是否将假定浏览器将要请求css / js文件,并因此继续发送它(从而避免了额外的请求)?

In short - can anyone explain when would the load time NOT increase by having separate css/js files and if it always increases, then is the load time increase proportional to the number of files included? 简而言之-有人能解释为什么单独的css / js文件不会导致加载时间增加,如果总是增加,那么加载时间的增加是否与所包含文件的数量成正比?

regards, 问候,

JP J.P

  1. Yes, browsers using HTTP/1.1 should generally be using keep-alive connections. 是的,使用HTTP / 1.1的浏览器通常应使用保持活动连接。

  2. The server won't necessarily assume it; 服务器不一定会承担它。 the keep-alive should mean there isn't a separate DNS lookup - the file still gets requested. 保持活动状态应意味着没有单独的DNS查找-仍会请求该文件。

If properly configured, you should find (which can be verified with Firefox+Firebug for example) that the first request generates a normal download of those files, but subsequent requests generate HTTP 304 (File Not Modified) requests where the content has not changed since the last load and as such it should be available from cache. 如果配置正确,您应该发现(可以使用Firefox + Firebug进行验证)第一个请求生成了这些文件的正常下载,但是随后的请求生成了HTTP 304(文件未修改)请求,其内容自最后一次加载,因此应该可以从缓存中获取。

If it is a real concern, you may want to look into using Expires headers to specify long-life of the files, so the request never even gets made (not even the request to see if the file has changed) 如果确实有问题,您可能需要研究使用Expires标头指定文件的长寿命,因此甚至不会发出请求(甚至看不到文件是否已更改的请求)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM