Skip to content
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

With-Zones Example with Link Prefetch not working out of the box #4419

Closed
jmaguirrei opened this issue May 17, 2018 · 2 comments
Closed

With-Zones Example with Link Prefetch not working out of the box #4419

jmaguirrei opened this issue May 17, 2018 · 2 comments

Comments

@jmaguirrei
Copy link
Contributor

Hello, I have implemented this pattern on my deploys:

https://github.com/zeit/next.js/tree/canary/examples/with-zones

With the links with the prefetch attribute, like:

export default () => (
  <div>
    <Header />
    <p>This is our homepage</p>
    <div><Link prefetch href='/blog'><a>Blog</a></Link></div>
    <div><Link prefetch href='/about'><a>About us</a></Link></div>
    <img width={200} src={asset('/nextjs.png')} />
  </div>
)

I am getting the Page does not exists message in the console, so prefetch is not working.

This is because app A does not know about app B, cause they are reached with a proxy.

How to implement prefetch in this case?

Thanks.

@timneutkens
Copy link
Member

Prefetching doesn't work with zones. Since moving from zone-to-zone is a hard page refresh for various reasons, for example multiple zones could run multiple versions of Next.js, React and other dependencies.

@jmaguirrei
Copy link
Contributor Author

@timneutkens Despite you are right: prefetch doesn't work with zones, I am very convinced that splitting your app into multiple micro-services is a good strategy for mantaining/deploying/scaling purposes. So, how to get best of both?

Going to basics, there is actually a really simple workaround I found talking in Slack channel, that I want to share here for posterity.

You can simple include, in your Head component, this:

<link rel='preload' href='https://<your-website>/_next/YOUR_BUILD_ID/page/<your-page.js>' as='script'/>

This is new for me, so if you see any downside of this approach, please let me know!

@lock lock bot locked as resolved and limited conversation to collaborators May 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants