Skip to main content
Glama
generate-sw.ts1.39 kB
import path from 'node:path'; import { generateSW } from 'workbox-build'; async function buildSW() { console.log('🏗️ Generating Service Worker...'); const { count, size } = await generateSW({ // 1. Where to output the file swDest: path.join(process.cwd(), 'public/sw.js'), // 2. Where to look for files to cache globDirectory: '.next', globPatterns: ['static/**/*.*', 'server/pages/manifest.json'], globIgnores: ['**/node_modules/**/*', '**/*.map', 'server/middleware*'], // 3. Modifying URLS to match Next.js structure modifyURLPrefix: { 'static/': '/_next/static/', }, // 4. Cache Config (The important part!) // This tells Workbox to cache the Google Fonts, Images, etc. // automatically without you writing a template. runtimeCaching: [ { urlPattern: /^https?.*/, handler: 'NetworkFirst', options: { cacheName: 'offlineCache', expiration: { maxEntries: 200, }, }, }, ], // 5. PWA Essentials skipWaiting: true, // Update SW immediately clientsClaim: true, // Take control immediately cleanupOutdatedCaches: true, maximumFileSizeToCacheInBytes: 5 * 1024 * 1024, // 5MB limit per file }); console.log( `✅ Service Worker generated! Precaching ${count} files (${size} bytes)` ); } buildSW();

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server