You can configure Unpoly to handle all links and forms on the page.
This avoids full page loads where possible, resulting in a smoother navigation experience.
For developers this means having to use fewer [up-...]
attributes.
This page shows how to make handle Unpoly all interactive elements. It also explains how to configure smart defaults that work for most of your links and forms.
To follow all links on a page without requiring an [up-follow]
attribute:
up.link.config.followSelectors.push('a[href]')
There are some exceptions when links will still make a full page load under this setting:
[up-follow=false]
attribute. Also see boolean attributes.[download]
attribute or with a cross-origin [href]
.up.link.config.noFollowSelectors
.mousedown
To follow links on mousedown
instead of click
without an [up-instant]
attribute:
up.link.config.instantSelectors.push('a[href]')
Note that an instant link must also by followable, usually by giving it an [up-follow]
attribute or by configuring up.link.config.followSelectors
.
There are some exceptions when links still activate on click
under this setting:
[up-instant=false]
attribute.up.link.config.noInstantSelectors
.Note that if you have event listeners bound to click
on accelerated links, they will
no longer be called. You need to bind these listeners to mousedown
or, better, up:click
instead.
To preload all links on when hovering over them, without requiring an [up-preload]
attribute:
up.link.config.preloadSelectors.push('a[href]')
There are some exceptions when links will not be preloaded under this setting:
[up-preload=false]
attribute.up.link.config.noPreloadSelectors
.To handle all forms on a page without requiring an [up-submit]
attribute:
up.form.config.submitSelectors.push(['form'])
There are some exceptions when forms will still submit with a full page load under this setting:
[up-submit=false]
attribute.[action]
attribute.You may configure additional exceptions in up.form.config.noSubmitSelectors
.
Legacy code often contains JavaScript that expects a full page load whenever the user interacts with the page. When you configure Unpoly to handle all interaction, there will not be additional page loads as the user clicks a link or submits a form.
See Making JavaScripts work with fragment updates.
Following a link or submitting a form is considered navigation by default.
When navigating Unpoly will use defaults to satisfy the user's expectation regarding scrolling, history, focus, request cancelation, etc.
See navigation for a detailed breakdown of navigation defaults and how to customize them.