缩小/合并JS文件的最大大小 [英] max size of Minify/Combining JS Files

查看:64
本文介绍了缩小/合并JS文件的最大大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感兴趣的是一个文件的最小化/合并的最大大小是多少.所以我有多个js文件,我发现我需要按3-5个文件来制作大约2-3个文件.

I'm interested what is max size of Minify/Combining of one file. So I have a multiple js files and I find I need to make around 2-3 portion of files by 3-5 files.

推荐答案

这里确实没有硬的黄金法则.通常,您希望使用尽可能少的HTTP请求进行页面加载.但是,最终目标是使页面加载尽可能快.虽然减少请求数是关键,但这不是唯一的因素.例如,如果您的页面包含一个100k js文件,则没有CSS,没有图像,没有其他请求.如果该页面有4个25k js请求,则该页面将在大多数现代浏览器中更快地加载,因为这4个请求可以跨4个连接并行化.但是,您的典型网页有30到100个请求,合并文件会大大加快请求的加载速度,因为大多数浏览器每个主机最多只能连接6个连接,打开新连接以及阻止javascript和css的问题取决于延迟浏览器类型,在加载js或css之前不会启动任何其他连接.这还取决于这些资源是否在头上.

There is really no hard, golden rule here. Typically, you want to make a page load with as few HTTP requests as possible. However the Ultimate goal is to make a page load as fast as possible. While reducing request count is key, it is not the only factor. For example, if you had a page with one 100k js file, no css, no images, no other requests. That page will load more quickly in most modern browsers if the page had 4 25k js requests because the 4 requests can be parallelized accross 4 connections. However, your typical web page has 30 to 100 requests and these will load much faster by combining files because most browsers are limited to 6 connections per host and there is latency involved in opening new connections as well as blocking issues with javascript and css depending on browser type where no other connections will be initiated until the js or css is loaded. This can also depend on if these resources are in the head or not.

因此,这全部取决于您的页面和目标浏览器.就个人而言,我将50k作为单个CSS或JS的最大大小.诚然,这不是非常科学.这是一个不错的整数,我发现它可以容纳几个典型的css或js文件,并且大小不大,以至于无法接受.

So it all depends on your page and your target browsers. Personally, I use 50k as a max size for a single css or js. This admittedly is not extremely scientific. Its a nice round number and one that I find accomodates several typical css or js files and is not so big that it is prohibitive.

这篇关于缩小/合并JS文件的最大大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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