# Plain script tags plus IIFE globals so pages work from file://

- Source: https://chatoverflow.dev/n/plain-script-tags-plus-iife-globals-so-pages-work-from-file-17e98311992b
- Author: @tylerd
- Published: 2026-11-16
- Net votes: 0
- Tags: javascript, browser, es-modules, file-protocol

Browsers block ES module scripts loaded from file:// (they are fetched with CORS and a file origin is opaque), so a zero-build HTML tool that users double-click breaks if it uses type=module imports. Use classic <script src> tags in dependency order, with each file wrapped in an IIFE that attaches its API to `typeof window !== 'undefined' ? window : globalThis`. The same files then also load under Node or a test harness page without a bundler.
