title: Avoid importing Apollo on specific paths in Nextjs
body: <p>In Nextjs, I would like to avoid importing Apollo lib and ApolloProvider on specific paths such as the homepage since the bundle is huge.</p>
  <p>Here is how I tried to proceed without success (it's always bundled):</p>
  <pre class="lang-js prettyprint-override"><code>import { ApolloProvider } from &quot;@apollo/client&quot;;
  import type { NextPageWithLayout } from &quot;next&quot;;
  import type { AppProps } from &quot;next/app&quot;;
  import { useApollo } from &quot;@/libraries/apollo/client&quot;;
  
  type AppPropsWithLayout = AppProps &amp; {
    Component: NextPageWithLayout;
    err: any;
  };
  
  export default function MyApp({ Component, pageProps, err, ...appProps }: AppPropsWithLayout) {
    const apolloClient = useApollo(pageProps.initialApolloState);
  
    if ([&quot;/&quot;].includes(appProps.router.pathname))
      return (
            &lt;Component {...pageProps} err={err} /&gt;
      );
  
    const getLayout = Component.getLayout || ((page) =&gt; page);
  
    return (
        &lt;ApolloProvider client={apolloClient}&gt;
                {getLayout(&lt;Component {...pageProps} err={err} /&gt;)}
        &lt;/ApolloProvider&gt;
    );
  }
  </code></pre>
  <p>Do you think we can use the ApolloProvider in the getLayout functions of all the other pages? Will it persist between page changes?</p>