birkir / gatsby-source-prismic-graphql

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

Performance improvement - defer prismic.min.js ? #180

Open mad-gav opened 4 years ago

mad-gav commented 4 years ago

I'm getting lighthouse warnings for the prismic file thats included. Is there any chance of adding a defer to the script so it's not render blocking?

Presumably this is only needed for the preview part?

image

madeleineostoja commented 4 years ago

You can set omitPrismicScript to true in the source config to stop it eager-loading the prismic script. I haven't seen any negative repercussions in doing that in my own projects, not sure why it's not the default

ohlr commented 4 years ago

@seaneking does it brake the previews?

madeleineostoja commented 4 years ago

It didn’t when I was using it, though I’ve since moved to gatsby-source-prismic which uses its own preview layer

birkir commented 4 years ago

It will break previews, yes. Hence, undocumented.

Here is a classic setup: a) production site with omitPrismicScript set to true and previews disabled b) setup a staging site with everything working well.

But adding a defer would be fine, what does Prismic say, is it required? @arnaudlewis

ohlr commented 4 years ago

Here is a classic setup: a) production site with omitPrismicScript set to true and previews disabled b) setup a staging site with everything working well.

I would love to see that in the docs @birkir .

dev-kylo commented 4 years ago

Hi yes, also having same issue with my performance reports. Any update on the defer? Thanks! report

DanielJohnsson87 commented 4 years ago

Adding defer would be much appreciated!

ohlr commented 4 years ago

@DanielJohnsson87, @kylorobs this PR addresses your issue. I have not tested however if it breaks something.

ohlr commented 4 years ago

What you could do in the meantime I guess is the following: set: omitPrismicScript: true, and include the prismic script yourself with https://www.gatsbyjs.org/packages/gatsby-plugin-react-helmet/