Edit this page

up.fragment up.reload([target], [options])
JavaScript function

Replaces the given element with a fresh copy fetched from the server.

By default, reloading is not considered a user navigation and e.g. will not update the browser location. You may change this with { navigate: true }.

Example

let { fragment } = await up.reload('.inbox')
console.log("New .inbox element: ", fragment)

Controlling the URL that is reloaded

Unpoly remembers the URL from which a fragment was loaded, so you don't usually need to pass a URL when reloading.

To reload from another URL, pass a { url } option or set an [up-source] attribute on the element being reloaded or its ancestors.

Skipping updates when nothing changed

Your server-side app is not required to re-render a request if there are no changes to the cached content.

By supporting conditional HTTP requests you can quickly produce an empty response for unchanged content.


Parameters

[target] stringorElementorArray<Element>orjQuery optional

The element that should be reloaded.

If omitted, an element matching a selector in up.fragment.config.mainTargets will be reloaded.

When an Element object is passed, a target selector will be derived.

[options] Object optional

See options for up.render().

[options.url] string optional

The URL from which to reload the fragment. This defaults to the URL from which the fragment was originally loaded.

[options.data] Object optional

Overrides properties from the new fragment's [up-data] with the given data object.

[options.keepData] boolean optional

Preserve the reloaded fragment's data object.

Properties from the new fragment's [up-data] are overridden with the old fragment's [up-data].

[options.navigate=false] string optional

Whether the reloading constitutes a user navigation.

Return value

A promise that fulfills with an up.RenderResult once the fragment has been reloaded and rendered.