Browser troubleshooting

Why a page opened from disk behaves differently

A page opened with a file URL can have different origin, storage, and fetch behavior from the same page served over HTTP. Test a website through a local server before diagnosing deployment behavior from a disk-opened file.

Worked example

Browser console example · use a disposable page on your own site

console.log(location.protocol);
console.log(location.origin);
console.log(new URL("./data.json", location.href).href);

How it works

The protocol reveals whether the page is using file, HTTP, or HTTPS. Origin-dependent features follow browser rules that are not identical for local files. A local HTTP server makes relative requests and routing closer to a real hosted site.

Limits and mistakes

Localhost is not identical to production: HTTPS, headers, redirects, and server rewrites can still differ. File-URL localStorage behavior is not a reliable cross-browser contract. Do not disable security settings as a substitute for serving the page properly.

Check the result

Compare the same small page opened from disk and through a local server. Inspect protocol, request results, and storage availability separately rather than attributing every difference to JavaScript syntax.

Sources

Reference documentation for the behavior used in this guide: