FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

docs: cache family endpoint by header · unjs/unifont@7ca0b38 · GitHub

/ unifont Public

Commit 7ca0b38

Browse files
committed
docs: cache family endpoint by header
1 parent 5d053a2 commit 7ca0b38

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

‎docs/nuxt.config.ts‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,9 @@ const vercelMarkdownRoutes = [
4949
headers: { vary: 'Accept, Accept-Encoding' },
5050
}))
5151

52-
/** The facets a family can be narrowed by, which a cache of one has to key on. */
53-
const familyFacets = ['weights', 'subsets', 'styles', 'provider']
54-
5552
/** A day: a family's faces change when a provider republishes it, and a deployment resets this. */
5653
const DAY = 60 * 60 * 24
5754

58-
// The endpoint answers in a format as well, which the page does not ask about.
59-
const familyEntry = { expiration: DAY, allowQuery: [...familyFacets, 'formats'] }
60-
6155
/**
6256
* Where the font caches live. `node_modules` is convenient in development but read-only on most
6357
* deployment platforms, where the temporary directory is the one writable path.
@@ -149,7 +143,6 @@ export default defineNuxtConfig({
149143
'/api/v1/**': { headers: { link: '</openapi.json>; rel="service-desc"; type="application/json"' } },
150144
'/api/v1/catalogue.css': { headers: { 'cache-control': 'public, max-age=3600, stale-while-revalidate=86400' } },
151145
'/fonts/**': { headers: { 'cache-control': `public, s-maxage=${DAY}, stale-while-revalidate=${DAY}` } },
152-
'/api/v1/fonts/*': { isr: familyEntry },
153146
},
154147
prerender: {
155148
routes: staticRoutes,

‎docs/server/api/v1/fonts/[family]/index.get.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ export default defineEventHandler(async (event) => {
4242
const fallbackCss = await metricFallbackCss(family, resolved.fonts, resolved.fallbacks ?? [])
4343
const entry = await lookupFamily(family)
4444

45-
// Long enough that a hover prefetch and the navigation behind it are one request.
46-
event.res.headers.set('cache-control', 'public, max-age=300, stale-while-revalidate=3600')
45+
/*
46+
* Long enough that a hover prefetch and the navigation behind it are one request, and long
47+
* enough at the edge to answer for a family no provider has republished. A header rather than an
48+
* `isr` route rule: that rewrites the request to a URL carrying no query string, so every
49+
* narrowed facet is answered with the defaults.
50+
*/
51+
event.res.headers.set('cache-control', 'public, max-age=300, s-maxage=86400, stale-while-revalidate=86400')
4752

4853
return {
4954
family,

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL