javascript Web 应用程序的推荐 JS kb 限制是多少?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5939161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 18:51:56  来源:igfitidea点击:

What is the recommended JS kb limit for a web app?

javascriptlimitfilesize

提问by wilsonpage

Just wondering if anyone more experienced out there could suggest a recommended limit for total JS resources in a web app. I want to make sure I'm not overloading my bandwidth.

只是想知道是否有更有经验的人可以建议 Web 应用程序中总 JS 资源的推荐限制。我想确保我的带宽没有超载。

I'm currently around 350 - 400kb spread between two .js files (unminified). This is not including jQuery & jQuery UI from Google CDN.

我目前在两个 .js 文件(未缩小)之间传播大约 350 - 400kb。这不包括来自 Google CDN 的 jQuery 和 jQuery UI。

Thanks!

谢谢!

回答by Alex KeySmith

I suppose there isn't really a recommended "file size" per-say.

我想每个人都没有真正推荐的“文件大小”。

More a recommended length of time for your entire page to load, including all css, images, javascript, rendering time etc. Too long and people are going to loose interest, but it really depends on your content i.e. if it's very specific content that people are after, then they will wait for longer, but if your running an e-commerce site and your competition is only a click away, then page-load times are very important.

更多推荐整个页面加载的时间长度,包括所有 css、图像、javascript、渲染时间等。太长了人们会失去兴趣,但这真的取决于你的内容,即人们是否是非常具体的内容之后,他们会等待更长的时间,但是如果您运行的是电子商务网站并且您的竞争对手只需点击一下鼠标,那么页面加载时间就非常重要。

I suppose the answer is make your files as small as possible and your site load as fast as possible. But this is going to be a classic return on investment question, if your running an e-commerce site, a faster loading site could lead to more sales?

我想答案是让您的文件尽可能小,并尽可能快地加载您的网站。但这将是一个典型的投资回报问题,如果您运行的是电子商务网站,加载速度更快的网站可能会带来更多的销售额吗?

But to try and answer your question, 400KB seems a little heavy to me. As a general rule of thumb, you want to aimfor sub 10 secondfor a sub 2 second load time of the page beginning to be visible - to at least give a response to your user.

但是要尝试回答您的问题,400KB 对我来说似乎有点重。作为一般的经验法则,你要瞄准的子10秒的开始是可见的页面的附属2的第二负载时间-至少给你的用户的响应。

Here are Yahoo's Best Practices for Speeding Up Your Web Site

以下是雅虎加速网站最佳实践

You can also run Y-Slow a firebug add-on, or numerous other speed tests to analyse and give recommendations.

您还可以运行 Y-Slow 一个 firebug 插件,或许多其他速度测试来分析和给出建议。

Google's Page Speed siteis a more contemporary approach to page speed.

Google 的 Page Speed 网站是一种更现代的页面速度方法。

回答by Mike Hofer

I believe it's around 500kb, at which point you start taking serious performance hits.

我相信它大约为 500kb,此时您开始严重影响性能。

回答by Alexei Levenkov

It is not clear if you are looking for page rendering performance or cost for your hosting advise...

目前尚不清楚您是在寻找页面渲染性能还是托管建议的成本...

For both: all your static files (CSS, JS, images) should be minified and served compressed (in case of images make sure you choose smallest acceptable size) if you are expecting site to be high traffic. Setting correct caching headers is important too.

对于两者:如果您希望站点具有高流量,则所有静态文件(CSS、JS、图像)都应该被缩小并压缩(如果是图像,请确保选择最小的可接受大小)。设置正确的缓存头也很重要。

Page rendering - see Alex Key's answer.

页面渲染 - 请参阅 Alex Key 的回答。

Cost of hosting - you are the one to figure out what is acceptatble. It is relatively easy to estimate - number of users per period of time multiplied by average download size from your site wil give you the number. You can also consider putting static content on some CDN.

托管成本 - 您是要弄清楚什么是可以接受的。估计相对容易 - 每段时间的用户数乘以您网站的平均下载大小,即可得出该数字。您还可以考虑将静态内容放在某些 CDN 上。