diff --git a/packages/gitbook/src/routes/ogimage.tsx b/packages/gitbook/src/routes/ogimage.tsx
index 9edfafdd4..b9679c564 100644
--- a/packages/gitbook/src/routes/ogimage.tsx
+++ b/packages/gitbook/src/routes/ogimage.tsx
@@ -206,7 +206,7 @@ export async function serveOGImage(baseContext: GitBookSiteContext, params: Page
{/* Grid */}
@@ -323,3 +323,22 @@ async function readImage(response: Response) {
const base64 = Buffer.from(arrayBuffer).toString('base64');
return `data:image/${response.headers.get('content-type')};base64,${base64}`;
}
+
+const staticImagesCache = new Map();
+
+/**
+ * Read a static image and cache it in memory.
+ */
+async function readStaticImage(url: string) {
+ const cached = staticImagesCache.get(url);
+ if (cached) {
+ return cached;
+ }
+
+ const response = await fetchSelf(url);
+ const image = await readImage(response);
+ console.log('readStaticImage', url, image);
+ staticImagesCache.set(url, image);
+
+ return image;
+}