Skip to content

Commit

Permalink
npm uninstall next-pwa
Browse files Browse the repository at this point in the history
next-pwa was last updated in August 2022.
There is also an issue which mentions that next-pwa is abandoned (?): shadowwalker/next-pwa#482

But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us.
It even lead to a bug since pages were cached without our knowledge.

So I will go with a different PWA approach. This different approach should do the following:
- make it more transparent what the service worker is doing
- gives us more control to configure the service worker and thus making it easier
  • Loading branch information
ekzyis committed Jun 20, 2023
1 parent 431947e commit e63f584
Show file tree
Hide file tree
Showing 5 changed files with 385 additions and 4,029 deletions.
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,3 @@ envbak
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml

# auto-generated files by next-pwa / workbox
public/sw.js
public/sw.js.map
public/workbox-*.js
public/workbox-*.js.map
public/worker-*.js
public/fallback-*.js
230 changes: 104 additions & 126 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const { withPlausibleProxy } = require('next-plausible')
const withPWA = require('next-pwa')
const defaultRuntimeCaching = require('next-pwa/cache')

const isProd = process.env.NODE_ENV === 'production'
const corsHeaders = [
Expand All @@ -19,128 +17,108 @@ const commitHash = isProd
? Object.keys(require('/opt/elasticbeanstalk/deployment/app_version_manifest.json').RuntimeSources['stacker.news'])[0].match(/^app-(.+)-/)[1] // eslint-disable-line
: require('child_process').execSync('git rev-parse HEAD').toString().slice(0, 4)

module.exports = withPWA({
dest: 'public',
register: true,
customWorkerDir: 'sw',
runtimeCaching: [
{
urlPattern: /\/_next\/data\/.+\/.+\.json$/i,
handler: 'NetworkFirst',
options: {
cacheName: 'next-data',
expiration: {
maxEntries: 32,
maxAgeSeconds: 24 * 60 * 60 // 24 hours
}
module.exports = withPlausibleProxy()({
env: {
NEXT_PUBLIC_COMMIT_HASH: commitHash
},
compress: false,
experimental: {
scrollRestoration: true
},
generateBuildId: isProd ? async () => commitHash : undefined,
// Use the CDN in production and localhost for development.
assetPrefix: isProd ? 'https://a.stacker.news' : undefined,
async headers () {
return [
{
source: '/_next/:asset*',
headers: corsHeaders
},
{
source: '/Lightningvolt-xoqm.ttf',
headers: [
...corsHeaders,
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable'
}
]
},
{
source: '/.well-known/:slug*',
headers: [
...corsHeaders
]
},
{
source: '/api/lnauth',
headers: [
...corsHeaders
]
},
{
source: '/api/lnurlp/:slug*',
headers: [
...corsHeaders
]
}
]
},
async rewrites () {
return [
{
source: '/faq',
destination: '/items/349'
},
{
source: '/story',
destination: '/items/1620'
},
{
source: '/privacy',
destination: '/items/76894'
},
{
source: '/changes',
destination: '/items/78763'
},
{
source: '/guide',
destination: '/items/81862'
},
{
source: '/daily',
destination: '/api/daily'
},
{
source: '/.well-known/lnurlp/:username',
destination: '/api/lnurlp/:username'
},
{
source: '/.well-known/nostr.json',
destination: '/api/nostr/nip05'
},
{
source: '/.well-known/web-app-origin-association',
destination: '/api/web-app-origin-association'
},
{
source: '/~:sub',
destination: '/~/:sub'
},
{
source: '/~:sub/:slug*',
destination: '/~/:sub/:slug*'
}
},
...defaultRuntimeCaching.filter((c) => c.options.cacheName !== 'next-data')
]
})(
withPlausibleProxy()({
env: {
NEXT_PUBLIC_COMMIT_HASH: commitHash
},
compress: false,
experimental: {
scrollRestoration: true
},
generateBuildId: isProd ? async () => commitHash : undefined,
// Use the CDN in production and localhost for development.
assetPrefix: isProd ? 'https://a.stacker.news' : undefined,
async headers () {
return [
{
source: '/_next/:asset*',
headers: corsHeaders
},
{
source: '/Lightningvolt-xoqm.ttf',
headers: [
...corsHeaders,
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable'
}
]
},
{
source: '/.well-known/:slug*',
headers: [
...corsHeaders
]
},
{
source: '/api/lnauth',
headers: [
...corsHeaders
]
},
{
source: '/api/lnurlp/:slug*',
headers: [
...corsHeaders
]
}
]
},
async rewrites () {
return [
{
source: '/faq',
destination: '/items/349'
},
{
source: '/story',
destination: '/items/1620'
},
{
source: '/privacy',
destination: '/items/76894'
},
{
source: '/changes',
destination: '/items/78763'
},
{
source: '/guide',
destination: '/items/81862'
},
{
source: '/daily',
destination: '/api/daily'
},
{
source: '/.well-known/lnurlp/:username',
destination: '/api/lnurlp/:username'
},
{
source: '/.well-known/nostr.json',
destination: '/api/nostr/nip05'
},
{
source: '/.well-known/web-app-origin-association',
destination: '/api/web-app-origin-association'
},
{
source: '/~:sub',
destination: '/~/:sub'
},
{
source: '/~:sub/:slug*',
destination: '/~/:sub/:slug*'
}
]
},
async redirects () {
return [
{
source: '/statistics',
destination: '/satistics?inc=invoice,withdrawal',
permanent: true
}
]
}
})
)
]
},
async redirects () {
return [
{
source: '/statistics',
destination: '/satistics?inc=invoice,withdrawal',
permanent: true
}
]
}
})
Loading

0 comments on commit e63f584

Please sign in to comment.