@elken/next-offline
Version:
<h1 align="center"> next-offline </h1>
38 lines (35 loc) • 828 B
JavaScript
const withOffline = moduleExists('next-offline')
? require('next-offline')
: {};
const nextConfig = {
workboxOpts: {
swDest: 'static/service-worker.js',
runtimeCaching: [
{
urlPattern: /^https?.*/,
handler: 'networkFirst',
options: {
cacheName: 'https-calls',
networkTimeoutSeconds: 15,
expiration: {
maxEntries: 150,
maxAgeSeconds: 30 * 24 * 60 * 60, // 1 month
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
},
}
module.exports = moduleExists('next-offline')
? withOffline(nextConfig)
: nextConfig
function moduleExists(name) {
try {
return require.resolve(name);
} catch (error) {
return false;
}
}