As the title suggests, I deployed my site but it fails to load the sound effects.
Active Site: https://syntaxwarrior30.github.io/Documentation-Wizard/
This is how I try to load the sound effects from the public folder, in src/DocsGen.jsx
:
DocsGen.jsx
Line 30 | const successAudio = new Audio('/public/Success.wav');
Line 31 | const errorAudio = new Audio('/public/Error.wav');
I have also tried:
DocsGen.jsx
Line 30 | const successAudio = new Audio('/Success.wav');
Line 31 | const errorAudio = new Audio('/Error.wav');
Both resulted in Failed to load resource: the server responded with a status of 404 ()
in console
2
Answers
I fixed the 404 loading error. Reference code below:
Public folder is a special folder in react which is outside of the scope of react bundle.
To use assets inside public folder you just directly reference them.
Here is a relevant thread: How to import and play all audio files from a directory in React?