Detailed answer
Inspect the request and console first.
Confirm src resolves to JavaScript rather than an HTML fallback page, and look for loading restrictions or syntax errors. Defer helps a classic script that needs parsed content. Fix the earliest failure before treating every missing behavior as a separate bug.
Example
<script src="/scripts/preview.js" defer></script>
Understanding the behavior
Separate loading failures from execution failures. A script may load successfully and then stop at an earlier exception, query an element before it exists or be blocked by a policy. Module imports introduce additional URL and MIME requirements.
Practical implementation notes
Start with the first console error and inspect the corresponding request. Add a small observable test near the entry point, then follow execution toward the failing interaction rather than changing several unrelated settings at once.
How to check it
Inspect the script response before debugging its functions or event handlers.
Expected result
The script URL returns JavaScript, not a catch-all HTML route.
Watch out: A catch-all router may return HTML for a missing script URL.
Read the reference ↗