简体   繁体   English

未使用的javascript函数会降低网页性能吗?

[英]Can unused javascript functions slow down page performance?

Trying to choose the right theme: I have a main javascript file with an amount of 500kb. 尝试选择正确的主题:我有一个主要的javascript文件,大小为500kb。 In this file are many functions, which are not being used on the current site. 此文件中有许多功能,当前站点上未使用它们。

Beside the additional load on page load: Can these unused functions slow down the performance? 除了页面加载的额外负载:这些未使用的功能还会降低性能吗?

Can unused functions require RAM or CPU usage on visitors end, even if they are not used, for example because they're storing variables? 未使用的函数是否可以要求访问者端使用RAM或CPU,即使不使用它们也是如此,例如因为它们存储变量?

Yes, because these functions are still being downloaded by the browser and stored in memory of the page in the browser. 是的,因为这些功能仍由浏览器下载并存储在浏览器页面的内存中。

But mind you, they probably won't have a big effect, so purging the javascript may not lead to a noticable increase, unless your users are visiting the site with a really slow internet connection or something. 但是请注意,它们可能不会发挥很大的作用,因此清除javascript可能不会导致明显的增长,除非您的用户使用非常慢的Internet连接访问网站。

Beside the additional load on page load: Can these unused functions slow down the performance? 除了页面加载的额外负载:这些未使用的功能还会降低性能吗?

Beside the additional load on page load? 除了页面加载的额外负载? Only if the user is on an extremely memory-starved device. 仅当用户使用内存不足的设备时。 500k of JavaScript code doesn't translate into much memory usage for the parsed result at all, the effect of it sitting in memory will, in all but the most unusual environments, be effectively zero. 500k的JavaScript代码根本不会转化为解析结果所需的大量内存,在大多数情况下(除最不寻常的环境外),驻留在内存中的效果实际上为零。

But two points on the thing you were leaving out with that "beside" comment: 但是,关于遗漏的“旁观”评论,有两点:

  • Downloading the unnecessary code; 下载不必要的代码; could have a noticeable effect on a slower connection. 可能会对较慢的连接产生明显影响。
  • Parsing (and possibly compiling) the unnecessary code; 解析(并可能编译)不必要的代码; could have a very small effect on the apparent page load, on a device with a really slow processor or a browser with a really slow JavaScript engine. 在处理器速度非常慢的设备或JavaScript引擎速度非常慢的浏览器上,这可能对外观上的页面加载影响很小。

But effectively, in the vast majority of environments, just having the extra functions around won't cause a noticeable effect at all. 但是有效的是,在绝大多数环境中,仅具有多余的功能根本不会引起明显的效果。 It's primarily downloading the unnecessary program text that will be noticeable. 它主要是下载不必要的程序文本,这些文本将引起注意。

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

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