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

Improve readme.md #1256

Closed
wants to merge 38 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
11248cd
Use logo as title; improve alt text
Feb 22, 2017
fe1de6f
Rewrite introduction
Feb 22, 2017
d4e3917
Add t.o.c. heading and placeholder
Feb 22, 2017
f0b18ab
Rewrite Getting Started guide
Feb 22, 2017
750fe2f
Rename How To Use section
Feb 22, 2017
b211124
Remove section Automatic code splitting
Feb 22, 2017
bcef4fa
Change wording for CSS section
Feb 22, 2017
1723bd4
Reword Static Files Serving section
Feb 22, 2017
15e534b
Make CSS section title consistent with following
Feb 22, 2017
0785c9a
Change wording+layout for Populating head section
Feb 22, 2017
4291dc5
Rewrite Fetching Data section
Feb 22, 2017
bb90b7b
Rewrite Routing section
Feb 22, 2017
108b59c
Reword Prefetching Pages section
Feb 22, 2017
bf5708c
Improve programmatic API docs
Feb 22, 2017
d95efea
Reword Custom document section
Feb 22, 2017
20f4a0d
Extend Error Handling section
Feb 22, 2017
83c05ac
Fix typo
Feb 22, 2017
d815375
Restructure Configuration section
Feb 23, 2017
003e357
Restructure Production Deployment section
Feb 23, 2017
acbeaa3
Extend contributing section
Feb 23, 2017
320bb76
Add T.O.C.
Feb 23, 2017
9bd1f46
Reword introduction
Feb 23, 2017
9790c3e
Fix typo
Feb 23, 2017
74a66d7
Fix wording in Getting Started guide
Feb 23, 2017
5df3aae
Fix typo, change wording
Feb 23, 2017
a8edf7f
More typo and wording fixes.
Feb 23, 2017
a6c1beb
Add markup consistency throughout info blocks
Feb 23, 2017
0393efe
Update headings for more consistency
Feb 23, 2017
6a54f05
More heading fixes
Feb 23, 2017
f16c406
Fix typos in introductions
Feb 23, 2017
10f3ae8
Fix wording, typo in Getting Started guide
Feb 23, 2017
6b3ec2f
Remove falsely added file
Feb 23, 2017
fba23e4
Merge remote-tracking branch 'upstream/master' into fix/docs
Feb 23, 2017
ef0a90f
Add missing readme updates from upstream commits
Feb 23, 2017
a3ff438
Resolve merge conflicts
Feb 28, 2017
48b4546
Document new prefetch behavior
Feb 28, 2017
88f82d3
readme: Fix method definition
Feb 28, 2017
17cc708
Fix merge conflict (#2)
timneutkens Mar 16, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 30 additions & 16 deletions readme.md
Expand Up @@ -341,50 +341,64 @@ Router.onRouteChangeError = (err, url) => {
<ul><li><a href="./examples/with-prefetching">Prefetching</a></li></ul>
</details></p>

Next.js has an API which allows you to prefetch pages.
Next.js exposes an API to prefetch pages.

Since Next.js server-renders your pages, this allows all the future interaction paths of your app to be instant. Effectively Next.js gives you the great initial download performance of a _website_, with the ahead-of-time download capabilities of an _app_. [Read more](https://zeit.co/blog/next#anticipation-is-the-key-to-performance).
> Since Next.js server-renders your pages, this allows all the future interaction paths of your app to be instant. Effectively Next.js gives you the great initial download performance of a _website_, with the ahead-of-time download capabilities of an _app_. [Read more](https://zeit.co/blog/next#anticipation-is-the-key-to-performance).

> With prefetching Next.js only download JS code. When the page is getting rendered, you may need to wait for the data.
:information_source: When prefetching, Next.js only downloads the code. Once the page is getting rendered you may still need to wait for data.

#### With `<Link>`
#### Using the `<Link>` Component

You can add `prefetch` prop to any `<Link>` and Next.js will prefetch those pages in the background.
To prefetch a route substitute your usage of [`<Link>`](#using-the-link-component) with the default export of `next/prefetch`. For example:

```jsx
import Link from 'next/link'
// components/navigation.js
import Link from 'next/prefetch'

// example header component
export default () => (
<nav>
<ul>
<li><Link prefetch href='/'><a>Home</a></Link></li>
<li><Link prefetch href='/about'><a>About</a></Link></li>
<li><Link prefetch href='/contact'><a>Contact</a></Link></li>
<li><Link href='/'><a>Home</a></Link></li>
<li><Link href='/about'><a>About</a></Link></li>
<li><Link href='/contact'><a>Contact</a></Link></li>
</ul>
</nav>
)
```

#### Imperatively
When this higher-level `<Link>` component is first used, the `ServiceWorker` gets installed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is obsolete since #957

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed an update to address this.


Most prefetching needs are addressed by `<Link />`, but we also expose an imperative API for advanced usage:
The `<Link>` component from `next/prefetch` accepts an additional boolean property `prefetch`. This enables turning off prefetching on a per-`<Link>` basis.

```jsx
import Router from 'next/router'
<Link href='/contact' prefetch={false}><a>Home</a></Link>
```

#### Imperatively Using `prefetch` Function

Most needs are addressed by using `<Link>`. With the `prefetch` function we also expose an imperative API for advanced usage:

```jsx
// pages/my-page.js
import { prefetch } from 'next/prefetch'

export default ({ url }) => (
<div>
<a onClick={ () => setTimeout(() => url.pushTo('/dynamic'), 100) }>
A route transition will happen after 100ms
<a onClick={ () => setTimeout(() => url.pushTo('/dynamic'), 1000) }>
Click here and a route transition will happen after 1s...
</a>
{
// but we can prefetch it!
Router.prefetch('/dynamic')
prefetch('/dynamic')
}
</div>
)
```

The API is defined as follows:

- `prefetch(url: string): void` &ndash; Prefetches given url.

### Custom server and routing

<p><details>
Expand Down