Skip to content

JavaScript Not Loading

Quick summary

Your script tag points to a file that doesn't exist, has a syntax error, or is blocked from loading — the page's interactivity breaks.

Why this happens

  • Wrong src path in the <script> tag

  • The JS file returns a 404 or a syntax error prevents execution

  • The script tag is placed before the DOM elements it references

Minimal example

✗ Broken code
<script src="/js/app.js"></script>  // file is main.js
✓ Fixed code
<script src="/js/main.js" defer></script>

The file is main.js, not app.js — the browser gets a 404. Adding defer ensures the script runs after the DOM is parsed.

How to diagnose

  • Check the Network tab for a 404 on the JS file

  • Look for syntax errors in the browser console

  • Verify the script tag is in the correct location (end of <body> or with defer)

How to fix

  • Correct the src path to the actual file location

  • Fix any syntax errors in the JS file

  • Add defer or move the <script> tag to the end of <body>

How to prevent

  • Use build tools to bundle and verify script paths

  • Use the defer attribute on scripts that don't need to run immediately

Related Resources

Related Glossary

Related Lessons

  • JavaScript

    Learn how JavaScript runs in the browser

Related Practice

← Back to language