Skip to content

feat: Support Cloudflare Pages deployment via generalized asset chunking#63

Merged
PDFCraftTool merged 2 commits intoPDFCraftTool:mainfrom
geneliu:main
Apr 14, 2026
Merged

feat: Support Cloudflare Pages deployment via generalized asset chunking#63
PDFCraftTool merged 2 commits intoPDFCraftTool:mainfrom
geneliu:main

Conversation

@geneliu
Copy link
Copy Markdown
Contributor

@geneliu geneliu commented Apr 8, 2026

PR Description: Support Cloudflare Pages via Asset Chunking
Problem
Cloudflare Pages imposes a hard 25 MiB file size limit on static assets. Currently, the LibreOffice WASM bundle (specifically soffice.wasm and soffice.data) exceeds this limit, even when compressed (~27MB and ~47MB). This makes document conversion tools (Word/Excel/PPT to PDF) broken when deployed to Cloudflare Pages.

Solution: Transparent Asset Chunking
This PR introduces a generalized asset chunking mechanism that splits any large files into smaller parts during the build process and reassembles them on the client side.

Key Components
Build-time Splitter: scripts/chunk-assets.mjs

Recursively scans the out/ directory after the Next.js export.
Identifies any file larger than 24 MiB.
Splits these files into 20 MiB parts (.part_0, .part_1, etc.).
Generates a .manifest.json for each chunked file and deletes the original.
Client-side Reassembler: src/lib/utils/asset-loader.ts

Introduces fetchAssembledBlob(url) which transparently checks for a .manifest.json before fetching an asset.
If a manifest exists, it fetches all chunks in parallel and reassembles them into a single Blob.
If no manifest exists (e.g., in local development or other hosting environments), it falls back to a standard fetch.
Correctly handles MIME types for WASM, JS, and Fonts.
Integration: src/lib/libreoffice/converter.ts

Updated to use fetchAssembledBlob for all LibreOffice assets.
Manages blob: URLs for the reassembled data and ensures they are revoked during cleanup.
Benefits
Full Cloudflare Pages Support: Document conversion now works "out of the box" on Cloudflare.
Cross-platform Compatibility: The solution is transparent and falls back to standard loading on platforms without the 25MB limit (Vercel, Netlify, Docker).
Zero Configuration: The chunking happens automatically as part of the build script.
Performance/Memory Considerations
Memory: Reassembly happens in the browser's memory. While this increases peak memory usage during initialization, it is unavoidable on length-limited hosts and is manageable given the WASM engine's existing memory requirements.
Network: Parallel fetching of chunks minimizes the performance impact of multiple requests.
Verification
Verified on Cloudflare Pages (Success).
Verified on local development (Success).
Verified npm run build generates correct parts and manifests.

@PDFCraftTool PDFCraftTool merged commit 16a83bd into PDFCraftTool:main Apr 14, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants