The up.link
module lets you build links that update fragments instead of entire pages.
In a traditional web application, the entire page is destroyed and re-created when the user follows a link:
This makes for an unfriendly experience:
Unpoly fixes this by letting you annotate links with an [up-target]
attribute. The value of this attribute is a CSS selector that indicates which page
fragment to update. The server still renders full HTML pages, but we only use
the targeted fragments and discard the rest:
With this model, following links feels smooth. All DOM state outside the updated fragment is preserved. Pages also load much faster since the DOM, CSS and JavaScript environments do not need to be destroyed and recreated for every request.
Let's say we are rendering three pages with a tabbed navigation to switch between screens:
Your HTML could look like this:
<nav>
<a href="/pages/a">A</a>
<a href="/pages/b">B</a>
<a href="/pages/b">C</a>
</nav>
<article>
Page A
</article>
Since we only want to update the <article>
tag, we annotate the links
with an up-target
attribute:
<nav>
<a href="/pages/a" up-target="article">A</a>
<a href="/pages/b" up-target="article">B</a>
<a href="/pages/b" up-target="article">C</a>
</nav>
Note
Instead of
article
you can use any other CSS selector like#main .article
.
With these [up-target]
annotations Unpoly only updates the targeted part of the screen.
The JavaScript environment will persist and the user will not see a white flash while the
new page is loading.
Follows this link with JavaScript and updates a fragment with the server response.
Follows this link on mousedown
instead of click
("Act on press").
Preloads this link before the user clicks it. When the link is clicked, the response will already be cached, making the interaction feel instant.
Follows the given link with JavaScript and updates a fragment with the server response.
A click
event that honors the [up-instant]
attribute.
Enables keyboard interaction and other accessibility behaviors for non-interactive elements that represent clickable buttons.
Follows this link as fast as possible.
A placeholder for content that is loaded later from another URL.
Loads a [up-defer="manual"]
placeholder.
This event is emitted before an [up-defer]
placeholder loads its deferred content.
Add an [up-expand]
attribute to any element to enlarge the click area of a
descendant link.
Follows the given link with JavaScript and updates a fragment with the server response.
Follows this link with JavaScript and updates a fragment with the server response.
Makes any element behave like a hyperlink.
Follows this link on mousedown
instead of click
("Act on press").
Configures defaults for link handling.
This event is emitted when a link is followed through Unpoly.
Parses the render options that would be used to follow the given link, but does not render.
Returns whether the given link will be followed by Unpoly instead of making a full page load.
Returns whether the given link has a safe
HTTP method like GET
.
Makes sure that the given link will be followed by Unpoly instead of making a full page load.
Preloads the given link.
This event is emitted before a link is preloaded.
Preloads this link before the user clicks it. When the link is clicked, the response will already be cached, making the interaction feel instant.