From 11e9dcc5bccdba0980f45312f605692c69053576 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 23 Jan 2023 17:17:53 +0000 Subject: [PATCH] feat: cache first for ipfs requests --- next.config.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/next.config.js b/next.config.js index 6abe4c5c..e7a2f174 100644 --- a/next.config.js +++ b/next.config.js @@ -8,6 +8,7 @@ const execSync = require("child_process").execSync const withPWA = require("next-pwa")({ dest: "public", }) +const cache = require("next-pwa/cache") const lastCommitCommand = "git rev-parse HEAD" @@ -32,6 +33,7 @@ class UnoCSS { /** @type {import('next').NextConfig} */ module.exports = withBundleAnalyzer( + // @ts-ignore withPWA({ env: { APP_DESCRIPTION: pkg.description, @@ -72,6 +74,32 @@ module.exports = withBundleAnalyzer( pwa: { publicExcludes: ["*"], + dynamicStartUrl: true, + runtimeCaching: [ + { + urlPattern: /\/(ipfs)\/([^/?#]+)/i, + handler: "CacheFirst", + options: { + cacheName: "next-ipfs", + expiration: { + maxEntries: 64, + maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days + }, + }, + }, + { + urlPattern: /\/_next\/image\?url=.+%2Fipfs%2F([^/?#]+)$/i, + handler: "CacheFirst", + options: { + cacheName: "next-ipfs", + expiration: { + maxEntries: 64, + maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days + }, + }, + }, + ...cache, + ], }, }), )