Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
WP Rocket will cause click event being fired twice

I find a strange issue. When enable WP Rocket, the first time when I click the menu in the mobile version, the click event will be fired twice:

    function addEventListenerToElement(element, type, listener)
    {
        if (element) {
            element.addEventListener(type, listener);
        }
    }

    addEventListenerToElement(document.querySelector('.menu-toggle'), "click", function(event) {
        // Slide toggle main menu for mobile version
        DOMAnimations.slideToggle(document.querySelector('.mobile-nav'), 500);
        
        // Prevent the default action, such as follow a hyperlink
        event.preventDefault();
        
        // Prevent the current event from further propagation to outer DOM nodes
        event.stopPropagation();         
    
        //  2021-10-21: The following return false can be commented out since:
        //  1. addEventListener callback function does not need to return a value, see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback
        //  2. It is equivalent to event.preventDefault() + event.stopPropagation(). See https://stackoverflow.com/a/11184286/2704265
        //  We will not add comments for the following similar cases.
        //  return false;
    });

I perform the following test:

  1. When the page is first loaded in mobile phone, and I click the menu, the menu will slide down and the up again. And by adding the breakpoint at DOMAnimations.slideToggle, I find the event is fired twice. The next time when I click the menu, then the event will only be executed once.
  2. If disable WP Rocket, then the event will only be fired once.

Has any one encountered similar issues?

Update

The website with WP Rocket enabled can be found at https://www.datanumen.com

The website with WP Rocket disabled can be found at http://www.sybase-recovery.com

The two sites use the same JavaScript code.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda