Javascript 控制台是否会阻止页面呈现
我用下面的代码编写了一个html页面Javascript 控制台是否会阻止页面呈现,javascript,html,web-performance,Javascript,Html,Web Performance,我用下面的代码编写了一个html页面 <html> <header> <div class="logo"><a href="index.html" title="Coyle Appliance Repair"></a></div> <div class="phoneNumber"><h3 class="
<html>
<header>
<div class="logo"><a href="index.html" title="Coyle Appliance Repair"></a></div>
<div class="phoneNumber"><h3 class="numberHeader">call today for an appointment - same day service is available</h3>
<h1 class="number"><a href="tel:+1-555-555-5555">555-555-5555</a></h1></div>
<div class="greyStrip"><h2 class="motto">Serving the Twin Cities and western Wisconsin since 1982</h2></div>
</header>
<script>
((function demo () {
let a = 1
while (a < 10000) {
a++
console.log(a)
}
})())
</script>
<div class="mainContent"><h2 class="missionStatement">Full service restaurant and commercial kitchen repair. We service all cooking, food prep, warewash/dishroom, and
refrigeration equipment.</h2>
</div>
</html>
今天打电话预约-提供当天服务
自1982年起服务于双子城和威斯康星州西部
((功能演示){
设a=1
而(a<10000){
a++
控制台日志(a)
}
})())
全方位服务的餐厅和商业厨房维修。我们为所有烹饪、食物准备、餐具室/洗碗室和厨房提供服务
制冷设备。
问题是,保留和删除console.log(a)
是的,任何函数调用都会略微降低性能。在代码中,调用console.log大约10000次,这样会降低页面的性能。浏览器正在计算该循环的每次迭代,并运行其中的所有代码。每个函数都会使用一些东西,在本例中,您将调用该
控制台.log
10000次,这意味着浏览器必须至少执行10000计算
console.log
不会阻止页面呈现,但会妨碍页面呈现的性能,因此会出现闪烁效果
console.log如何影响性能:同样值得注意的是,
console.log
在旧浏览器中可能会导致更严重的问题(页面加载失败),因此,如果您在生产中不需要它,请将其取出,因为它是不必要的渣滓。@d_30如果这是您正在寻找的答案,请不要忘记将其标记为已接受。这对我和社区帮助很大。