loadImage silent failure when sketch served from subpath in production
0 reputation · 20 Dec 2022, 19:35 UTC
loadImage silent failure when sketch served from subpath
Goal: guarantee that loadImage, loadSound and similar preload calls resolve assets correctly whether the sketch runs on a local dev server or on a production host that serves the page from a subpath or with a different base href.
Constraints: p5.js resolves asset URLs relative to the HTML document’s base URL. In development the base is often /, while production may host the same page under /app/ or behind a reverse proxy that rewrites paths. The library offers no built‑in configuration to override this resolution, and the failure manifests as a silent 404 with no console error, leaving the sketch missing media.
Uncertainty: there is no documented API to set an asset root at runtime, and the behavior varies between global‑mode scripts and ES‑module imports.
What pattern makes asset paths resilient to base‑URL changes without hard‑coding absolute URLs?
Does p5.js expose a runtime method to define a custom asset prefix for preload functions?
How can a CI pipeline verify that all assets load successfully in a headless environment that mimics the production base path?