How I Built a 93 KB Client-Side GIF89a & WebCodecs Studio Without COOP/COEP Headers
Most browser-based GIF editors take one of two trade-offs: they either upload every frame to a remote processing server, or they ship a ~30 MB WebAssembly FFmpeg bundle that requires strict Cross-Origin-Opener-Policy and
Most browser-based GIF editors take one of two trade-offs: they either upload every frame to a remote processing server, or they ship a ~30 MB WebAssembly FFmpeg bundle that requires strict Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers.
While building Offline GIF Editor, I wanted a zero-upload studio that opens instantly under a strict 95 KB raw core JS budget, runs 100% locally in the browser with zero COOP/COEP headers, and still handles real-world edge cases like animated transparency disposal, chat file-size caps, and multi-format video exports.
Here are the four engineering decisions that made the biggest difference:
1. Keep an Immutable baseDelay Per Frame to Eliminate Speed Drift
GIF frame delays are quantized to centiseconds (10 ms ticks). If you multiply frame delays in place when a user clicks 2x and then 1x, rounding error accumulates quicklyβand custom loop repeat counts often get silently overwritten.
Instead, store each frame's original baseDelay separately and recompute active delays from that baseline whenever the user toggles 0.5x, 2x, 3x, or 1x. In the GIF Speed Changer, that keeps 2x -> 3x -> 1x bit-exact and preserves custom loop counts.
2. Edge-Connected Flood-Fill Transparency Instead of Global Chroma Key
Global color replacement ruins stickers and UI captures: removing white backgrounds also punches holes through eyes, highlights, or text labels.
Seeding a breadth-first flood fill strictly from the border pixels (plus optional click seeds) with a real-time canvas preview and auto-detected 5-color frame swatches solves this cleanly. You can test the live cutout behavior on the GIF Background Remover, where interior white pixels remain 100% opaque while border regions export clean GIF89a alpha.
3. Lazy-Load gifsicle-wasm Only When Compression Is Requested
Discord animated emojis cap at 256 KB and Slack animated emojis cap at 128 KiB. Shipping a WASM optimizer on initial page load hurts Core Web Vitals, so the core workbench boots with lightweight JS decoding/encoding (gifuct-js + gifenc) and only lazy-imports gifsicle-wasm-browser when the user opens the GIF Compressor or clicks an Auto-Fit preset.
4. Pure-JS Animated WebP/APNG Frame Compositing + WebCodecs MP4
Safari/WebKit still handles multi-frame transparent WebP and APNG inconsistently when drawn straight to a canvas. Extracting frame chunks in pure JS, decoding via createImageBitmap, and compositing disposal rectangles manually keeps 100% alpha parity across Chrome and WebKit in WebP to GIF, while WebCodecs handles hardware-accelerated H.264 exports in GIF to MP4.
Everything runs completely on-device with zero uploads and zero login at offlinegifeditor.com. Feedback from anyone else working with binary image codecs in the browser is very welcome!
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.