November 28, 2026
How to Deploy a Browser RAW Decoder With Workers and Safe Fallbacks
Deploy browser-based RAW decoding with a Web Worker, cross-origin isolation checks, and a tested fallback path for unsupported devices.
How to Deploy a Browser RAW Decoder With Workers and Safe Fallbacks
A browser RAW decoder should run off the main thread and should still give the user a useful result when threaded WebAssembly is unavailable. This guide shows how to put FlashRaw in a Web Worker, check cross-origin isolation before opting into a threaded build, and keep an embedded-preview or single-thread route as a deliberate fallback. You need a bundler that can emit a worker module, control of your response headers, and a small set of representative RAW files.
FlashRaw’s npm package supports browsers, Web Workers, and Node.js; its multi-threaded browser mode requires a cross-origin-isolated page. That makes deployment configuration part of the feature—not a detail to leave until launch.

1. Decide what happens on every capability branch
Do not make the upload button promise one outcome. A RAW file may be unsupported, the browser may not be cross-origin isolated, or a large file may exceed the device’s practical memory budget. Write the user-visible result for each case before wiring the decoder.
| Condition | Decode route | Expected result |
|---|---|---|
| Worker and threaded WASM available | Worker with the threaded-capable build | Responsive UI while the decode runs |
Worker available but crossOriginIsolated is false |
Worker with a non-threaded build | Decode can continue, with lower parallelism |
| Format or device cannot produce a full decode | Embedded preview or clear rejection | The user sees a preview or an actionable message |
The distinction matters: FlashRaw tracks support by format mode, bit depth, compression, and crop mode, not merely by filename extension. A .NEF or .DNG suffix alone is not your compatibility test.
Use the embedded preview as an optional fast path, not proof that a full RAW development will match a final export. FlashRaw documents both preview extraction and display-ready RGBA output in its browser and Node quick start.
2. Put file reading and decoding in a module worker
Keep the main thread responsible for file selection, progress state, cancellation controls, and painting the returned image. Transfer the file buffer to a module worker for opening and decoding. A minimal message boundary can look like this:
// raw-worker.js
import { FlashRaw } from "flashraw";
self.onmessage = async ({ data }) => {
try {
const raw = await FlashRaw.open(data.buffer);
const image = await raw.decode({
backend: "auto",
output: "rgba8"
});
self.postMessage(
{ type: "decoded", width: image.width, height: image.height, pixels: image.data.buffer },
[image.data.buffer]
);
raw.close();
} catch (error) {
self.postMessage({ type: "decode-error", message: String(error.message || error) });
}
};
// main.js
const worker = new Worker(new URL("./raw-worker.js", import.meta.url), { type: "module" });
fileInput.addEventListener("change", async () => {
const file = fileInput.files?.[0];
if (!file) return;
status.textContent = "Preparing RAW file…";
const buffer = await file.arrayBuffer();
worker.postMessage({ buffer }, [buffer]);
});
The expected result is simple: scrolling, cancel buttons, and status updates remain usable while the worker handles the expensive work. Keep the original File or create a new buffer if you need to retry, because transferring an ArrayBuffer hands ownership to the worker.

3. Enable isolation before you rely on WebAssembly threads
A worker alone does not mean a threaded WebAssembly build can use shared memory. Check window.crossOriginIsolated at startup and record the result in your support diagnostics. Browsers expose this property only when the document has the isolation conditions needed for features such as SharedArrayBuffer; see MDN’s cross-origin isolation reference.
For a site you control, start with these document response headers and test all of your third-party assets afterward:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy separates the browsing context from cross-origin opener relationships, while Cross-Origin-Embedder-Policy: require-corp requires embedded cross-origin resources to opt in through CORS or CORP. Review the current COOP and COEP behavior for your hosting setup.
Deploy those headers in a staging environment first. Fonts, analytics scripts, payment widgets, iframes, and CDN-hosted assets are common reasons an otherwise correct header change breaks a page. The expected result is window.crossOriginIsolated === true on the exact production origin, with all required embeds still loading.
const threadedPath = window.crossOriginIsolated;
const mode = threadedPath ? "threaded-worker" : "single-thread-worker";
console.info({ mode, crossOriginIsolated: window.crossOriginIsolated });
FlashRaw’s documented platform support explicitly describes browser, worker, and Node operation, with multithreading where the page is cross-origin isolated. Do not market the fallback as a failure: it is the route that makes the feature usable on deployments that cannot set those headers.
4. Add a bounded fallback instead of retrying forever
Use the worker response to choose the next meaningful action. For a decode error, first offer an embedded preview when the file has one; otherwise show the format, camera, and original error in a support-friendly message. For an out-of-memory or policy problem, recommend a smaller file, server-side processing, or a supported desktop flow rather than looping the same decode.
A practical order is:
- Try metadata or an embedded preview for immediate feedback.
- Attempt a full decode in the worker using the mode chosen at startup.
- If the exact fixture is unsupported, tell the user that support varies by compression and mode, then retain the file-selection state.
- If the page is not isolated, retain the single-thread worker route; do not ask the user to change browser settings.
This approach complements the private browser RAW preview architecture and the earlier guide on keeping browser RAW work responsive with a worker. The deployment difference here is intentional: responsiveness is only one part of a launch-ready capability contract.
5. Test the deployed origin with a fixture matrix
Before release, collect files that represent the cameras and modes you actually accept. Include at least one ordinary success case, one large file, one compressed variant, and one file expected to fail gracefully. Verify the version, camera model, compression mode, response headers, browser, and decode route in your test notes.

Use this release checklist:
- The production page reports the expected
crossOriginIsolatedvalue. - The module worker and WebAssembly files return successful responses from the production origin.
- A successful fixture keeps the UI responsive and returns dimensions and pixels.
- A known unsupported fixture produces a clear, non-destructive result.
- The no-isolation route is tested on purpose, not discovered by a customer.
- Preview output and full decode output are labeled as different operations.
If you need to compare decoder speed, keep that as a separate, reproducible exercise. FlashRaw publishes benchmark methodology and per-format caveats; decode-to-sensor and RAW-to-display-RGB are different workloads, and a result from one machine is not a production guarantee.
Ship the capability contract, not just the decoder
A solid browser RAW feature is a worker boundary, an isolation check, a fallback, and a real fixture matrix. Start with FlashRaw’s browser demo and package documentation to validate a supported file locally, then add the worker boundary and headers to staging before you promote the feature. Your next action is to test crossOriginIsolated on the deployed origin and record exactly what your user sees when it is false.