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

152
Visualizações
Only load sound effect for a the button that need that sound

I'm trying to increase the performance of my site. I got about ~87 right now accordingly Google Page Speed Insight. While it's not the worst, it's not great either. One of the issues is loading too much assets and only use only 1, or 2 of them

enter image description here

{{-- Audio --}}
<audio id="audio-poop" src="/assets/be/img/baby/sound/poop.wav" autostart="false" ></audio>
<audio id="audio-pee" src="/assets/be/img/baby/sound/pee.wav" autostart="false" ></audio>
<audio id="audio-feed" src="/assets/be/img/baby/sound/feed.wav" autostart="false" ></audio>
<audio id="audio-medicine" src="/assets/be/img/baby/sound/medicine.wav" autostart="false" ></audio>
<audio id="audio-done" src="/assets/be/img/baby/sound/done.wav" autostart="false" ></audio>
<audio id="audio-delete" src="/assets/be/img/baby/sound/delete.wav" autostart="false" ></audio>
<audio id="audio-swipe" src="/assets/be/img/baby/sound/swipe.wav" autostart="false" ></audio>
<audio id="audio-forward" src="/assets/be/img/baby/sound/forward.wav" autostart="false" ></audio>
<audio id="audio-jump" src="/assets/be/img/baby/sound/jump.wav" autostart="false" ></audio>
<audio id="audio-sleep" src="/assets/be/img/baby/sound/sleep.wav" autostart="false" ></audio>
<audio id="audio-solidfood" src="/assets/be/img/baby/sound/solidfood.wav" autostart="false" ></audio>

I check my sites networks tab, I see that it loaded all of these. Those are mini sound effect that I called only when user clicked on specific buttons. Is there a way to only load them when user click on a button that need them ?

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use directly in javascript using the Audio API:

function playSound() {
    const sound = new Audio(path);
    sound.play();
}

In this way, the audio file will only load when the button is clicked.

about 4 years ago · Juan Pablo Isaza Relatório
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