Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Producing massive webpack bundles #284

Closed
TimUnderhay opened this issue Feb 28, 2018 · 10 comments
Closed

Producing massive webpack bundles #284

TimUnderhay opened this issue Feb 28, 2018 · 10 comments

Comments

@TimUnderhay
Copy link

TimUnderhay commented Feb 28, 2018

Thanks very much for this great library!

Using version 4.1.2 of ng2-pdf-viewer, it seems to be producing enormous bundles using "ng-build --prod --aot" (using Angular 5.2 and CLI 1.7.1). Webpack-bundle-analyzer tells me that under *.chunk.js - pdf.worker.js is 1.42 MB and in the main bundle, pdf.js is using 573 K. (screenshot attached).

I found this issue where it was marked as addressed but I've been unable to reduce the size in my case.

I'm certainly open to the possibility that I'm doing something wrong, but I can't think of what.

@VadimDez
Copy link
Owner

Are you using custom workerSrc for pdf worker? Are you using default path that gets pdf worker from https://cdnjs.cloudflare.com ?

@TimUnderhay
Copy link
Author

I've tried it without workerSrc and also with workerSrc. My current is:

(<any>window).PDFJS.workerSrc = '/node_modules/pdfjs-dist/build/pdf.worker.min.js';

But that is a directive for the browser. I don't think it would have any effect on the AOT compiler.

@TimUnderhay
Copy link
Author

TimUnderhay commented Feb 28, 2018

I realise now that since it's webpack, I can't point directly to node_modules. I've updated it to:

(<any>window).PDFJS.workerSrc = 'resources/pdf.worker.min.js';

I've confirmed that in the browser, it's now loading pdf.worker.min.js from the local resources/ dir rather than from cloudflare, but there's still that same large pdf.worker chunk in the bundle, which I'm guessing is just redundant code.

@VadimDez
Copy link
Owner

Could you please check whether pdf.worker.js chunk is actually loaded/used?

@TimUnderhay
Copy link
Author

Sure thing; the network tab shows that *chunk.js is not being loaded, but /resources/pdf.worker.min.js is.

@VadimDez
Copy link
Owner

I guess pdf.worker.js chunk is loaded (fallback) only when pdf worker is disabled

@TimUnderhay
Copy link
Author

Are you referring to pdf webworker? As in, if webworker is disabled, it will use the chunk to render in the normal browser js thread?

@TimUnderhay
Copy link
Author

I guess since it isn't being loaded anyway, it isn't really a problem. I'll just stick with dumping the minified worker in my resources dir and pointing to it.

Along the lines of the bundle size, there's one thing I'd like to request: could you please provide a way to disable the import of of compatibility.js? My Angular application only supports the latest Firefox and Chrome releases, so I have no need for it to be there. Anywhere I can save space on my bundle size is a good thing :)

@TimUnderhay
Copy link
Author

Closing issue as I will now just load worker_min.js from my resources/ dir, and the worker chunk should never get loaded by the client browser.

@GauravThakur03
Copy link

Try Adobe Embed APIs: https://www.adobe.com/devnet-docs/dcsdk_io/viewSDK/index.html

  • Much smaller
  • Easy to integrate
  • Much better PDF View quality
  • Lots of PDF features

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

No branches or pull requests

3 participants