-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Service worker (custom Astro integration) #242
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # src/components/PerfHead/PerfHead.astro
Deploying head-start with
|
Latest commit: |
4f9c35a
|
Status: | ✅ Deploy successful! |
Preview URL: | https://92cd60c5.head-start.pages.dev |
Branch Preview URL: | https://feat-199-add-service-worker.head-start.pages.dev |
…build fail if building the service worker fails
remove forced error (used to test registration error handling)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and works well! I pushed some basic documentation and added comments with a few more suggestions.
} | ||
|
||
export const GET: APIRoute = async () => { | ||
const output = await esbuild.build({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The esbuild.build
config between dev and prod are (and should be) mostly the same (only minify
and sourcemap
are different). Should we move the shared config up to the root?
const buildConfig = {
entryPoints: [srcFilename],
outdir: outFilename,
target: ['es2020'],
bundle: true,
write: false,
allowOverwrite: true,
}
and use that in both places to keep everything in sync?, like:
const output = await esbuild.build({
...buildConfig,
minify: false,
sourcemaps: false,
});
cacheName: 'pages', | ||
plugins: [ | ||
new CacheableResponsePlugin({ | ||
statuses: [0, 200], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider a package like http-status-codes
to write StatusCodes.OK
instead of 200
? Or simply use some const
s at the top, like statusOpaque = 0;
and statusOk = 200
? Or does this only complicate things?
(ironically that package doesn't have the opaque response status; I also had to look that up. So maybe a comment or link on that would be helpful instead)
self.addEventListener('activate', (event) => { | ||
event.waitUntil(self.clients.claim()); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed caching assets as well. Do we want to add that to this PR? Something like:
registerRoute(
({ request }) => request.url.pathname.startsWith('/_astro/'),
new CacheFirst({
cacheName: 'assets',
plugins: [
new CacheableResponsePlugin({
statuses: [0, 200],
}),
new ExpirationPlugin({
maxEntries: 50,
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days
}),
],
})
);
What would be good expiration settings?
Or should we match immutable
responses instead? Like:
registerRoute(
async ({ request, response }) => {
if (!response) return false;
const cacheControl = response.headers.get('cache-control');
return cacheControl?.split(' ').includes('immutable') ?? false;
},
/* ... same */
);
import { NetworkFirst } from 'workbox-strategies'; | ||
import { CacheableResponsePlugin } from 'workbox-cacheable-response'; | ||
import { ExpirationPlugin } from 'workbox-expiration'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add config that makes cache cleanup easier in the future? Like:
import { setCacheNameDetails } from 'workbox-core';
import pkg from '@root/package.json';
setCacheNameDetails({
prefix: pkg.name,
suffix: 'v1',
});
Changes
Associated issue
Resolves #199
How to test
Checklist