Is there a way to async load PDF.js similar to pdf.worker.js? PDF.js is about 200kb, which is too large for me.
margintopt opened this issue · comments
Before you start - checklist
- I understand that React-PDF does not aim to be a fully-fledged PDF viewer and is only a tool to make one
- I have checked if this feature request is not already reported
Description
// pdj.ts in react-pdj
import * as pdfjsModule from 'pdfjs-dist';
const pdfjs = (
'default' in pdfjsModule ? pdfjsModule['default'] : pdfjsModule
) as typeof pdfjsModule;
export default pdfjs;
Proposed solution
<script src="//mozilla.github.io/pdf.js/build/pdf.mjs" type="module"></script>external script load pdf.js
Alternatives
No response
Additional information
No response
There's no direct way of doing this in v7. It will be possible with v8 as pdf.js 4.x supports it. Until then, perhaps lazy load the entire component?
There's no direct way of doing this in v7. It will be possible with v8 as pdf.js 4.x supports it. Until then, perhaps lazy load the entire component?
Can I clone the library myself and then use webpack external to reduce the size of the pdfjs part?
I guess you could! I don't know much about this process, but react-pdf is open source and everything is allowed, feel welcome to experiment!
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.