Opening index.html directly creates a file:// page, not a small website. JavaScript modules, fetch(), server-side PHP, MIME types, absolute paths, and origin checks can therefore behave differently than they do through http://localhost.
Last updated: November 7, 2026.
# From the directory that contains index.html:
python -m http.server 8000
# Then open this URL in the browser:
http://localhost:8000/
# Alternative when Node.js is available:
npx http-server -p 8000 -c-1Use a server only on a trusted development machine and stop it when finished. If the project contains PHP, use PHP’s development server or the same web-server stack used by the application rather than a static-file server.
Check the browser console and network panel
MDN’s local testing server guide explains that browsers restrict asynchronous requests and included local files under file://. Modern browsers commonly treat local files as opaque origins, so two files in the same folder are not guaranteed to be same-origin.
The MDN module guide requires web modules to be served with a JavaScript MIME type and notes that they are subject to CORS. A failed module path may also return HTML instead of JavaScript. Inspect the first console error and the failed request’s status, content type, and resolved URL before changing code.
Fix paths instead of weakening security
Prefer relative project paths such as ./assets/app.js. A leading slash begins at the server’s document root and does not mean the folder beside the HTML file. Match filename capitalization because deployment servers may be case-sensitive even when a local Windows folder is not.
Do not disable browser security or add mode: "no-cors" as a general fix; an opaque response cannot be read by JavaScript. If a remote API is involved, configure CORS on the server you control or call it through an application backend. If PHP source appears in the page, the request is being served by a static server rather than a PHP interpreter.
Continue with fixing local asset 404 errors, calling a server route with Fetch, and sharing CSS across HTML pages.