Pagefold

Options

Every option you can pass to new Pagefold(), with its default.

const pagefold = new Pagefold({ /* options */ })
OptionTypeDefaultWhat it does
containersstring[]['#pagefold']Selectors of the content areas replaced on each visit. Every page needs all of them.
linkSelectorstring'a[href]'Which elements start a visit when clicked.
linkToSelf'scroll' | 'navigate''scroll'What a link to the current page does: scroll to the top, or load it again.
ignoreVisit(url, { el, event }) => booleanignores [data-no-pagefold]Return true to leave a visit to the browser.
pluginsPlugin[][]Plugins to install.
hooksobject{}Hook handlers to register. Add .before, .once or .replace to a hook name for options.
animationSelectorstring | false'[class*="transition-"]'Elements whose CSS transitions and animations are awaited. false waits for nothing.
animationScope'html' | 'containers''html'Where the state classes go.
animateHistoryBrowsingbooleanfalseAnimate and scroll back and forward visits.
nativebooleanfalseUse the View Transitions API when the browser has it.
cachebooleantrueKeep visited pages in memory.
cacheMaxnumbernoneKeep at most this many pages, dropping the least recently used.
cacheTtlnumbernoneForget cached pages after this many milliseconds.
failOnStatus(status) => booleanstatus === 500Which response statuses fail a visit, so the browser loads the page normally.
requestHeadersRecord<string, string>X-Requested-With: pagefold, Accept: text/html, application/xhtml+xmlHeaders sent with every page request.
queue'latest' | 'all' | 'ignore''latest'What a visit does when another is already on screen: only the last waits, all wait in order, or it is dropped (details).
timeoutnumber0Request timeout in milliseconds. 0 means none.
resolveUrl(url) => stringidentityRewrite URLs before they are loaded or cached, to treat /en/about and /about as one page, for example.
skipPopStateHandling(event) => booleanskips entries Pagefold did not createReturn true to ignore a back or forward event.

Start from your goal

I want to…Set
The fastest feelThe Preload plugin. The cache is already on
Keep memory low on a big sitecacheMax and cacheTtl (why)
Animate with GSAP, Motion or the Web Animations APIanimationSelector: false and the JS plugin
Let the browser animatenative: true (View Transitions)
Animate the back button tooanimateHistoryBrowsing: true
Replace more than one areacontainers: ['#main', '#sidebar']
Leave a part of the site to the browserignoreVisit
Treat 404 as a failurefailOnStatus: (status) => status >= 400
Ignore clicks while a page is animatingqueue: 'ignore'
Not wait forever for a slow servertimeout: 8000
Treat /en/about and /about as one pageresolveUrl

Common setups

// Several containers: all must exist in every page
new Pagefold({ containers: ['#main', '#sidebar'] })

// Treat every client error as a failure
new Pagefold({ failOnStatus: (status) => status >= 400 })

// Only handle links inside the main content
new Pagefold({ linkSelector: '#pagefold a[href]' })

// Skip some URLs
new Pagefold({ ignoreVisit: (url) => url.startsWith('/wp-admin') })

Changing options later

pagefold.options is a plain object, and most options are read when they are needed, so you can change it at any time. containers is read at the start of each visit; plugins and hooks are only read at startup: use pagefold.use(plugin) and pagefold.hooks.on(...) afterwards.