消除被动侦听器 JS 语法问题

问题描述

我正在尝试消除被动侦听器以提高滚动性能。但是每次我添加代码时,我的语法都会破坏我的主页滑块。这是我当前的集成语法:

<script>
function clean(node)
{
  for(var n = 0; n < node.childNodes.length; n ++)
  {
    var child = node.childNodes[n];
    if
    (
       child.nodeType === 8 
       || 
       (child.nodeType === 3 && !/\S/.test(child.nodeValue))
     )
     {
       node.removeChild(child);
       n --;
     }
     else if(child.nodeType === 1)
     {
       clean(child);
     }
   }
 }
 document.addEventListener("DOMContentLoaded",doClean);

 function doClean(){
     clean(document.body);
 }
 </script>

我尝试添加

document.addEventListener("touchstart",function(e) {
    console.log(e.defaultPrevented);  // will be false
    e.preventDefault();   // does nothing since the listener is passive
    console.log(e.defaultPrevented);  // still false
},Modernizr.passiveeventlisteners ? {passive: true} : false);

这极大地提高了我的页面得分。但就像我说的“它完全从主页中删除了我的滑块”。我想我只是没有正确编写 JS 语法。添加 2 个“document.addEventListener”没有意义吧?有什么建议吗?

我的网站:https://www.staging3.easyimportauto.com/

谢谢

这是我现在所处的位置(我有 2 个 EventListeners):

document.addEventListener("DOMContentLoaded",doClean);

   function doClean(){
       clean(document.body);
}
document.addEventListener("touchstart",function(e) {
   console.log(e.defaultPrevented);  // will be false
   e.preventDefault();   // does nothing since the listener is passive
   console.log(e.defaultPrevented);  // still false
},Modernizr.passiveeventlisteners ? {passive: false});

上述 JS 语法确实消除了 Google PageSpeed Insights 中的错误……但它仍然使我的 Revolution Slider/Banner 在主页上消失。我上面的代码一定还有错误吗?或者您认为这超出了 Passive Listener 添加的范围?嗯,哈哈

我的网站:https://www.staging3.easyimportauto.com/

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...