console.log会降低JavaScript的执行性能吗? [英] Will console.log reduce JavaScript execution performance?

查看:242
本文介绍了console.log会降低JavaScript的执行性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将使用调试功能 console.log 降低JavaScript执行性能?它会影响生产环境中脚本执行的速度吗?

Will use of the debugging feature console.log reduce JavaScript execution performance? Will it affect the speed of script execution in production environments?

是否存在从单个配置位置禁用生产环境中的控制台日志的方法?

Is there an approach to disable console logs in production environments from a single configuration location?

推荐答案

如果您要在公共站点或其他地方使用此功能,任何对使用开发人员工具知之甚少的人都可以阅读您的调试消息。根据您记录的内容,这可能不是理想的行为。

If you are going to have this on a public site or something, anyone with little knowledge on using the developer tools can read your debug messages. Depending on what you are logging, this may not be a desirable behavior.

最好的方法之一是包装 console.log 在你的一个方法中,你可以检查条件并执行它。在生产版本中,您可以避免使用这些功能。此 Stack 溢出问题详细介绍了如何使用关闭编译器

One of the best approaches is to wrap the console.log in one of your methods, and where you can check for conditions and execute it. In a production build, you can avoid having these functions. This Stack Overflow question talks in details about how to do the same using the Closure compiler.

所以,回答你的问题:


  1. 是的,它会降低速度,虽然只是可以忽略不计。

  2. 但是,不要不要使用它,因为它太容易让人阅读你的日志。

  3. 的答案这个问题可能会为您提供有关如何从生产中删除它们的提示。

  1. Yes, it will reduce the speed, though only negligibly.
  2. But, don't use it as it's too easy for a person to read your logs.
  3. The answers to this question may give you hints on how to remove them from production.

这篇关于console.log会降低JavaScript的执行性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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