Member-only story
Don’t install PDF dependencies, use this.
I will show you how to avoid useless dependencies in this silly example.
I remember that day when my PM came to the office and said to everyone that we needed to show a PDF file for viewing on our main page.
I as the lead frontend developer had to fulfill the PM’s wish.
I approached PM's office and asked, “What will the user do with this PDF file?”
He replied, “Just read, that’s it”.
Then, I looked up all the dependencies across npm and yarn packages that correspond to the functionality of displaying the PDF file.
Here is the list of what I found in the package manager search.
What I found interesting is all of them have a huge bundle size. What I mean is huge.
- react-pdf has 3.23 MB
- pdfkit has 5.9 MB
- jspdf-autotable has 253 kB
- @react-pdf/renderer has 2.33 MB
- pdfjs-dist has 36.5 MB
I fully agree that jspdf-autotable has the smallest bundle size. However, I came up with a solution that was much more suitable.
The solution is easy as possible.