feat: Support Cloudflare Pages deployment via generalized asset chunking#63
Merged
PDFCraftTool merged 2 commits intoPDFCraftTool:mainfrom Apr 14, 2026
Merged
feat: Support Cloudflare Pages deployment via generalized asset chunking#63PDFCraftTool merged 2 commits intoPDFCraftTool:mainfrom
PDFCraftTool merged 2 commits intoPDFCraftTool:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.