Skip to content

Commit

Permalink
Add more information to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mornir committed Feb 2, 2021
1 parent dc4c19f commit 03cd73b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $ yarn start
This project is built in the [Nuxt Full Static mode](https://nuxtjs.org/blog/going-full-static/), using the Nuxt crawler to detect every relative link and generat it.
It means that, in production, the website won't make any API call to Sanity. However, it will make an API call for every pages during build time. And those calls aren't made to the CDN because we always want to have the freshest data when content editors trigger a rebuid.

This approach is fine for websites with not too many pages. If your datastore contains 5000 products, then you'd better turn off the crawler and fetch all routes with a single API request:
This approach is fine for websites with not too many pages. If the datastore contains a lot of products, then it's better turn off the crawler and fetch all routes with a single API request:

```js
// nuxt.config.js
Expand Down Expand Up @@ -99,6 +99,17 @@ const client = createClient({
})
```

And don't forget to return the payload and thus prevent the API calls in your pages:

```js
asyncData({ $sanity, params, payload }) {
if(payload) return { product: localize(data) }
return $sanity
.fetch(query, params)
.then((data) => ({ product: localize(data) }))
},
```

## Note on GROQ query default limit

The queries are by default limited to 100 items. This project is just an example, but it is possible to expand it with pagination or forever-scroll. To get more items, just add ex [0..1000] to the end of your query https://www.sanity.io/docs/data-store/query-cheat-sheet#slice-operations

0 comments on commit 03cd73b

Please sign in to comment.