Riff / Built on the open web / Platform

Fetch

Swaps library views in from the REST route without a page load.

The Listen page: the library, nine albums as drawn record covers
This grid came from the library REST route; clicking a cover fetches that post and swaps it in.

How Riff uses it

The Listen app fetches the library and each post from the plugin's REST route with a JSON Accept header, and memoises each promise so going back is instant. A non-2xx response throws and the entry is dropped from the cache.

Why

Swapping views without a page load is what keeps the music playing, and the cache is why Back feels instant.

Without it

A failed fetch sends the browser to the real URL with a full navigation.

Where

Links open the source at the commit this page was published from.

Reference: Fetch on MDN.