<commit_before># curi-addon-prefetch

[![npm][badge]][npm-link]

[badge]: https://img.shields.io/npm/v/curi-addon-prefetch.svg
[npm-link]: https://npmjs.com/package/curi-addon-prefetch

The prefetch addon enables you to run a `uri`'s `load` function prior to actually navigating to that location. This is only useful for in-app navigation. If the user uses the browser's forward/back buttons, the loading will be handled within the Curi configuration object.

**Note:** If you use this addon, then your `load` functions should be caching the data. This is because the route's `load` function is always called when generating a response, effectively making a duplicate call.

## Installation

```js
npm install --save curi-addon-prefetch
```

### UMD

```html
<script src="https://unpkg.com/curi-addon-prefetch@0.1.0/umd/curi-addon-prefetch.js"></script>
<script type="text/javascript">
  const prefetch = window.CuriAddonPrefetch;
</script>
```

The version number above may not always be accurate. To ensure that you are using the most
up to date version of `curi-addon-prefetch`, open https://unpkg.com/curi-addon-prefetch/ in your
browser and manually navigate to the umd/curi-addon-prefetch.js file. That will provide you
with the URI of the most recent release. There is also a minimized version of the bundle
if you change the file name in the URI to "curi-addon-prefetch.min.js"

## Usage

```js
import createConfig from 'curi';
import prefetch from 'curi-addon-prefetch';

const history = ...;
const routes = [...];

const conf = createConfig(history, routes, { addons: [prefetch] });

// call a route's load function manually
conf.addons.prefetch('User', { params: { id: 2 } })
  .then(() => {
    // do something once the data is loaded
  })
```

This addon will only register routes that have a `load` function in their `load` object.

```js
// will register
{
  name: 'User',
  path: 'user/:id',
  load: (params) => {
    if (Store.has(params.id)) {
      return;
    }
    // fetch and store the data
    return fetch(`/api/user/${params.id}`)
      .then(resp => resp.json())
      .then(data => {
        Store.save(data);
      });
  }
}

// will NOT register
{
  name: 'User',
  path: 'user/:id'
}
{
  name: 'User',
  path: 'user/:id',
  preload: () => {
    return import('./components/User').then(resp => resp.default)
  }
}
```
<commit_msg>Fix prefetch addon doc [ci-skip]<commit_after># curi-addon-prefetch

[![npm][badge]][npm-link]

[badge]: https://img.shields.io/npm/v/curi-addon-prefetch.svg
[npm-link]: https://npmjs.com/package/curi-addon-prefetch

The prefetch addon enables you to run a `uri`'s `load` function prior to actually navigating to that location. This is only useful for in-app navigation. If the user uses the browser's forward/back buttons, the loading will be handled within the Curi configuration object.

**Note:** If you use this addon, then your `load` functions should be caching the data. This is because the route's `load` function is always called when generating a response, effectively making a duplicate call.

## Installation

```js
npm install --save curi-addon-prefetch
```

### UMD

```html
<script src="https://unpkg.com/curi-addon-prefetch@0.1.0/umd/curi-addon-prefetch.js"></script>
<script type="text/javascript">
  const prefetch = window.CuriAddonPrefetch;
</script>
```

The version number above may not always be accurate. To ensure that you are using the most
up to date version of `curi-addon-prefetch`, open https://unpkg.com/curi-addon-prefetch/ in your
browser and manually navigate to the umd/curi-addon-prefetch.js file. That will provide you
with the URI of the most recent release. There is also a minimized version of the bundle
if you change the file name in the URI to "curi-addon-prefetch.min.js"

## Usage

```js
import createConfig from 'curi';
import prefetch from 'curi-addon-prefetch';

const history = ...;
const routes = [...];

const conf = createConfig(history, routes, { addons: [prefetch] });

// call a route's load function manually
conf.addons.prefetch('User', { id: 2 })
  .then(() => {
    // do something once the data is loaded
  })
```

This addon will only register routes that have a `load` function in their `load` object.

```js
// will register
{
  name: 'User',
  path: 'user/:id',
  load: (params) => {
    if (Store.has(params.id)) {
      return;
    }
    // fetch and store the data
    return fetch(`/api/user/${params.id}`)
      .then(resp => resp.json())
      .then(data => {
        Store.save(data);
      });
  }
}

// will NOT register
{
  name: 'User',
  path: 'user/:id'
}
{
  name: 'User',
  path: 'user/:id',
  preload: () => {
    return import('./components/User').then(resp => resp.default)
  }
}
```

{'fraction_non_alphanumeric': 0.1417389464776814, 'fraction_numerical': 0.0016924053310767928, 'mean_word_length': 3.5947521865889214, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1995469', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1525, 'n_words': 519}