简体   繁体   中英

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. 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?

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.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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