---
area: "Learn"
parent: "Links chapter"
url: "https://unpoly.com/learn/handling-all-links"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [Links chapter](https://unpoly.com/learn/links.md)</nav>

# Handling all links

You can configure Unpoly to handle every link on the page, without annotating each link with an [`[up-follow]`](https://unpoly.com/api/up-follow.md) attribute.

Clicks then update fragments instead of loading full pages, and you need fewer `[up-...]` attributes in your HTML.

> #### Note
>
> Forms can be handled the same way. See [Handling all forms](https://unpoly.com/learn/handling-all-forms.md).

<nav aria-label="Contents">

#### Contents

- [Following all links](#following-all-links)
- [Following all links on `mousedown`](#following-all-links-on-mousedown)
- [Preloading all links](#preloading-all-links)
- [Making exceptions](#exceptions)
- [Using a macro instead](#macro)

</nav>

## Following all links {#following-all-links}

To follow _all_ links on a page without requiring an [`[up-follow]`](https://unpoly.com/api/up-follow.md) attribute:

```js
up.link.config.followSelectors.push('a[href]')
```

Some links will fall back to default browser behavior under this setting:

- Links with an `[up-follow=false]` attribute. Also see [boolean attributes](https://unpoly.com/learn/attributes-and-options.md#boolean-attributes).
- Links with a [`[download]`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download) attribute.
- Links with a [`[target]`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target) attribute (to target an iframe or open new browser tab).
- Links with a `javascript:`, `mailto:` or `tel:` scheme.
- Links with a cross-origin `[href]`.
- Links with an `[href]` that only contains a `#hash` (like `#` or `#section`) and don't also have local HTML in an `[up-document]`, `[up-fragment]`, or `[up-content]` attribute.
- Any additional exceptions configured in [`up.link.config.noFollowSelectors`](https://unpoly.com/api/up.link.config.md#config.noFollowSelectors).

Scripts that expect a full page load after every click need adjusting, see [Migrating legacy JavaScripts](https://unpoly.com/learn/legacy-scripts.md).

## Following all links on `mousedown` {#following-all-links-on-mousedown}

To follow links on `mousedown` instead of `click` without requiring an [`[up-instant]`](https://unpoly.com/api/up-instant.md) attribute:

```js
up.link.config.instantSelectors.push('a[href]')
```

Note that an instant link must also be [followable](https://unpoly.com/api/up.link.isFollowable.md), usually by giving it an [`[up-follow]`](https://unpoly.com/api/up-follow.md) attribute or by configuring [`up.link.config.followSelectors`](https://unpoly.com/api/up.link.config.md#config.followSelectors) as [shown above](#following-all-links).

Some links will still activate on `click` under this setting:

- Links with an `[up-instant=false]` attribute.
- Links that are not [followable](#following-all-links).
- Links with an `[onclick]` attribute.
- Any additional exceptions configured in [`up.link.config.noInstantSelectors`](https://unpoly.com/api/up.link.config.md#config.noInstantSelectors).

If you have event listeners bound to `click` on accelerated links, they will no longer be called. Bind these listeners to `mousedown` or, better, [`up:click`](https://unpoly.com/api/up:click.md) instead.

## Preloading all links {#preloading-all-links}

To preload _all_ links on hover, without requiring an [`[up-preload]`](https://unpoly.com/api/up-preload.md) attribute:

```js
up.link.config.preloadSelectors.push('a[href]')
```

Some links will not be preloaded under this setting:

- Links with an `[up-preload=false]` attribute.
- Links that are not [followable](#following-all-links).
- Links whose destination [cannot be cached](https://unpoly.com/api/up.network.config.md#config.autoCache).
- Any additional exceptions configured in [`up.link.config.noPreloadSelectors`](https://unpoly.com/api/up.link.config.md#config.noPreloadSelectors).

## Making exceptions {#exceptions}

You can still make exceptions by setting an `[up-follow=false]` attribute:

```html
<a href="/path" up-follow="false">Click for full page load</a>
```

`[up-instant=false]` and `[up-preload=false]` make exceptions from instant clicks and preloading in the same way.

## Using a macro instead {#macro}

Instead of changing [`up.link.config.followSelectors`](https://unpoly.com/api/up.link.config.md#config.followSelectors), you can register a [macro](https://unpoly.com/api/up.macro.md) that sets [`[up-follow]`](https://unpoly.com/api/up-follow.md) on every link:

```js
up.macro('a[href]:not([up-follow=false])', function(link) {
  link.setAttribute('up-follow', '')
})
```

Links with `[up-follow=false]` are left alone. The [exceptions above](#following-all-links) still apply: links with a `[target]` or a cross-origin `[href]` load a full page.

A macro can set other attributes in the same pass, like [`[up-preload]`](https://unpoly.com/api/up-preload.md) to preload the link on hover.

<nav aria-label="Reading order">

- [Previous: Following links](https://unpoly.com/learn/following-links.md)
- [Next: Preloading links](https://unpoly.com/learn/preloading.md)

</nav>

