Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!