10LOC

#http-caching

Web Platformadvanced

The Cache API for direct HTTP response caching

const CACHE_NAME = "api-cache-v1";

export const fetchWithCache = async (url: string, maxAgeMs: number) => {
  const cache = await caches.open(CACHE_NAME);
  const cached = await cache.match(url);

Cache real Response objects by URL from plain page scripts, with a manual max-age check, no service worker required.