queen-raae / gatsby-remark-oembed

A GatsbyJS Plugin that transforms oembed links into its corresponding embed code.
https://gatsby-remark-oembed.netlify.com/
MIT License
162 stars 25 forks source link

Lazy load the scripts needed for certain sources #91

Open rjyo opened 4 years ago

rjyo commented 4 years ago

Problem: When not all the pages need embedding, using SSR to add the scripts (on all pages) will damage the whole site's speed score (benchmarked with Google's PageSpeed Insights).

Solution: This PR will move the SSR injected scripts to the client side. As thus they will only be loaded on the pages(blogs) with embeds.

raae commented 4 years ago

I have been thinking it should be possible to check for the embeds server-side as well. Add a flag to the pages when embeds are processed.

I am a little afraid to check for things like blockquote.instagram-media as they might change the html we get back from their endpoints at any time.

raae commented 4 years ago

We might secretly add the elements to options, so if they break user can fix it by overriding the elements without having to wait for us to fix it.

nickytonline commented 3 years ago

Just following up on this PR. I like the idea of this as we should only be loading scripts that we require. Is this something you still want to work on @rjyo?