birkir / gatsby-source-prismic-graphql

Gatsby source plugin for Prismic GraphQL
MIT License
137 stars 75 forks source link

Reduce production bundle size #141

Open leo-cheron opened 4 years ago

leo-cheron commented 4 years ago

Hello,

Analysing the demo bundle with gatsby-plugin-webpack-bundle-analyser-v2 reveals the total bundle size to be about 638ko parsed. This package is now widely used and keeping its weight low should be a priority to ensure a fast load.

image

  1. The whole lodash library is loaded, for a total of ~70k parsed, but only get & pick seem to be used. Lodash dependency could be replaced by lodash.pick & lodash.get.

  2. The second largest dependency is Apollo and it's dependencies. I don't know if replacing it with graphql-react could be possible, but the saving would be worth investigating.

  3. Cherry on the cake: prismic.min.js and other scripts (such as jquery 😰) are loaded by default to display the preview panel. It has been tackled in this issue, and setting omitPrismicScript to true doesn't seem to break the preview. What that script does is unclear to me, but why not omitting it by default or at least document it to let this up to the user's choice? We may also imagine some cookie mechanic to load it only if we're in preview mode.

andyto commented 4 years ago

Is this line causing the problem with the whole lodash being loaded?

https://github.com/birkir/gatsby-source-prismic-graphql/blob/46854b8af8b2fe90e8f944060be792eb75042448/packages/gatsby-source-prismic-graphql/src/components/WrapPage.tsx#L2

leo-cheron commented 4 years ago

Is this line causing the problem with the whole lodash being loaded?

https://github.com/birkir/gatsby-source-prismic-graphql/blob/46854b8af8b2fe90e8f944060be792eb75042448/packages/gatsby-source-prismic-graphql/src/components/WrapPage.tsx#L2

Yep.

andyto commented 4 years ago

Created a merge request #144 to update it.