-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby-plugin-google-analytics): Add preconnect and dns-prefetch #12826
Conversation
Thanks for this PR 👍 |
Honestly I don't think this is needed, preconnect has hardly any downside and is done when the browser is idle and has time to do it. Most connections are kept in cache which means that preconnect is probably already done. @pgilad could you check your formatting rules as lots has changed which shouldn't be changed (see linting errors) |
Thanks @wardpeet - no auto formatting 😢 ? Oh I see we use |
@wardpeet That's
Pre-connecting to noncritical resource host can then block other DNS requests. |
@yogeshkotadiya it depends on how you look at it, the browser keeps the preconnect connection ready for 10s but there is more to it than that. The operating system is caching the dns. Also when using tls 1.3 the handshake will do 1 roundtrip instead of 2 which is also something the operating system will provide. Chrome dedicates 8 threads to dns resolution if not mistaken. I agree that preconnect shouldn't be thought of lightly but for a resource like analytics it's probably not bad as it mostly already is resolved and will be used in 10s. If you feel really strongly about this feel free to create a PR to disable it but it should be enabled by default. |
@wardpeet This makes sense, you made things very clear and I learned something also so thanks 👍 |
Holy buckets, @pgilad — we just merged your PR to Gatsby! 💪💜 Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! |
Added
preconnect
anddns-prefetch
link headers when using thegatsby-plugin-google-analytics
plugin. It's recommended by the Lighthouse tool, also see the discussion on #12802I also didn't like that all code had to be indented for the
process.env.NODE_ENV
check, so I changed it to early return (Sorry about that 😸 )