fix(media): serve the image-compression worker's script ourselves #12

Merged
genji1024 merged 1 commit from fix/image-compression-worker into main 2026-10-12 10:49:39 +09:00
Collaborator

Closes #11

Changes

  • client/src/media.ts: prepareImage passes libURL to browser-image-compression, pointing at the library's own UMD build (dist/browser-image-compression.js) imported with Vite's ?url, so it is emitted under /assets/ and served from our origin. The URL is made absolute because the library's worker runs from a blob: URL, where relative URLs do not resolve. Without this, the worker importScripts() the library from cdn.jsdelivr.net.

Verification

  • typecheck, lint, unit tests and build pass locally.
  • The build emits dist/assets/browser-image-compression-<hash>.js, byte-identical to the package's dist/browser-image-compression.js, and the bundle passes /assets/browser-image-compression-<hash>.js as the worker's script.
  • To check on this pull request's preview (https://pr-12.preview.genji1024.com/, the first real one from #9): post a picture and confirm in the browser's devtools that the worker loads the script from the preview's own /assets/ with no CSP violation and no fallback to the main thread.
Closes #11 ## Changes - **`client/src/media.ts`**: `prepareImage` passes `libURL` to `browser-image-compression`, pointing at the library's own UMD build (`dist/browser-image-compression.js`) imported with Vite's `?url`, so it is emitted under `/assets/` and served from our origin. The URL is made absolute because the library's worker runs from a `blob:` URL, where relative URLs do not resolve. Without this, the worker `importScripts()` the library from `cdn.jsdelivr.net`. ## Verification - typecheck, lint, unit tests and build pass locally. - The build emits `dist/assets/browser-image-compression-<hash>.js`, byte-identical to the package's `dist/browser-image-compression.js`, and the bundle passes `/assets/browser-image-compression-<hash>.js` as the worker's script. - To check on this pull request's preview (`https://pr-12.preview.genji1024.com/`, the first real one from #9): post a picture and confirm in the browser's devtools that the worker loads the script from the preview's own `/assets/` with no CSP violation and no fallback to the main thread.
fix(media): serve the image-compression worker's script ourselves
All checks were successful
ci / check (pull_request) Successful in 2m45s
8dd541f50b
browser-image-compression runs its worker from a blob: URL that
importScripts() the library from cdn.jsdelivr.net unless told otherwise,
so picking a picture ran third-party code from a CDN (and fell back to
the main thread, freezing the page, wherever the CDN was unreachable or
blocked by a CSP). Bundle the library's own UMD build as an asset and
pass its absolute URL as libURL. (#11)

Closes #11
genji1024 approved these changes 2026-10-12 10:49:12 +09:00
genji1024 left a comment

LGTM!

LGTM!
genji1024 deleted branch fix/image-compression-worker 2026-10-12 10:49:39 +09:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
genji1024/koto!12
No description provided.