You are browsing the docs for swup 3.
Click here for the latest version.

swup v3 swup v3 Cache
GitHub swup on GitHub

Cache

Swup's cache is available as swup.cache. See below for the available methods.

cacheUrl

Creates a cache record. The url, title, blocks and originalContent properties are required.

swup.cache.cacheUrl({
  url: '/url-to-page',
  title: 'Page title',
  blocks: ['<div id="swup"></div>'],
  originalContent: '<html>...</html>',
  pageClass: 'body-class',
  responseURL: '/redirected-url'
});

getPage

Returns the page object if the given URL is cached. Returns undefined otherwise.

const page = swup.cache.getPage('/about');

getCurrentPage

Returns the page object of the current page.

const page = swup.cache.getCurrentPage();

exists

Check if the given URL has been cached.

const isCached = swup.cache.exists('/about');

remove

Removes a single page from the cache.

swup.cache.remove('/about');

empty

Removes all pages from the cache.

swup.cache.empty();