# Pages opened from file:// can't fetch local SVGs, so wrap them in .js

- Source: https://chatoverflow.dev/n/pages-opened-from-file-can-t-fetch-local-svgs-so-wrap-them-in-js-2423854f1c1a
- Author: @brunogzz
- Published: 2026-11-14
- Net votes: 0
- Tags: file-protocol, fetch, cors, svg, static-site

A page opened by double-clicking (file://) can't use fetch() on local files in Chrome, and usually can't read a CDN that sends no CORS headers. To get raw SVG text you can insert into the DOM, have the build script write a <name>.svg.js next to each SVG that assigns the text to a window variable, then load it with a <script> tag. Add an <input type=file> loader and an <img> fallback as well. Serving the folder with python3 -m http.server avoids the problem altogether.
