{"id":19473178,"url":"https://github.com/cansin/next-with-offline","last_synced_at":"2025-04-25T12:31:30.913Z","repository":{"id":39406592,"uuid":"263076811","full_name":"cansin/next-with-offline","owner":"cansin","description":"A monorepo for tools needed to easily create a PWA with an offline view for Next.js + React.","archived":false,"fork":false,"pushed_at":"2023-01-06T05:36:01.000Z","size":4434,"stargazers_count":5,"open_issues_count":20,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T00:01:47.752Z","etag":null,"topics":["nextjs","offline","progressive-web-app","react","react-hooks","workbox"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cansin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-11T15:07:48.000Z","updated_at":"2022-10-03T11:46:24.000Z","dependencies_parsed_at":"2023-02-05T10:46:44.466Z","dependency_job_id":null,"html_url":"https://github.com/cansin/next-with-offline","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cansin%2Fnext-with-offline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cansin%2Fnext-with-offline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cansin%2Fnext-with-offline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cansin%2Fnext-with-offline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cansin","download_url":"https://codeload.github.com/cansin/next-with-offline/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250817669,"owners_count":21492197,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nextjs","offline","progressive-web-app","react","react-hooks","workbox"],"created_at":"2024-11-10T19:17:36.342Z","updated_at":"2025-04-25T12:31:29.902Z","avatar_url":"https://github.com/cansin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @next-with-offline \n[![build](https://img.shields.io/travis/com/cansin/next-with-offline)](https://travis-ci.com/github/cansin/next-with-offline) \n[![license](https://img.shields.io/github/license/cansin/next-with-offline)](https://github.com/cansin/next-with-offline/blob/master/LICENSE)\n\nA suite of libraries that enables you to have a Workbox, Next.js, and React based Progressive Web App\nwith basic offline support.\n\n- **[`@next-with-offline/next-plugin`](packages/next-plugin):** Next.js plugin for generating a Workbox.\n- **[`@next-with-offline/react-hook`](packages/react-hook):** React hook for registering/using a Workbox.\n- **[`@next-with-offline/service-worker`](packages/service-worker):** Code utilities for configuring a service worker.\n\n## Install\n\n```bash\nyarn add @next-with-offline/next-plugin @next-with-offline/react-hook  @next-with-offline/service-worker workbox-window\n```\n\n## Basic Usage\n\n1. Update or create `next.config.js` with:\n\n   ```js\n   const withOffline = require(\"@next-with-offline/next-plugin\");\n\n   module.exports = withOffline({\n     offline: {\n       path: \"/offline\",\n     },\n     // .\n     // ..\n     // ... other Next.js config\n   });\n   ```\n\n2. Add `public/sw.js` and `public/sw.js.map` to your `.gitignore`:\n\n   ```git\n   public/sw.js\n   public/sw.js.map\n   ```\n\n3. Create `worker.js` with:\n\n   ```js\n   import withNext from \"@next-with-offline/service-worker\";\n\n   withNext({ offlinePath: \"/offline\", showReloadPrompt: true });\n   ```\n\n4. Update or create `pages/_app.js` with:\n\n   ```js\n   import useWorkbox from \"@next-with-offline/react-hook\";\n   import { ThemeProvider } from \"@material-ui/core/styles\";\n   import { SnackbarProvider } from \"notistack\";\n\n   export default function App({ Component, pageProps }) {\n     useWorkbox({\n       offlinePath: \"/offline\",\n       showReloadPrompt() {\n         // A function that returns a Promise\n         // that resolves when user agrees to reload,\n         // or rejects if the user dismisses.\n       },\n     });\n\n     return \u003cComponent {...pageProps} /\u003e;\n   }\n   ```\n\n5. Create a basic `pages/offline.js` page:\n\n    ```js\n    import React from \"react\";\n    \n    export default function OfflinePage() {\n      return (\n        \u003cp\u003e\n          Oops, you appear to be offline. This app requires an internet connection.\n        \u003c/p\u003e\n      );\n    }\n    \n    export default Page;\n    ```\n\n### Available Options\n\n- **offlinePath:** string or boolean - a string pathname to the offline page.\n  Or `false` if you want to disable. \n  - defaults to `/offline`.\n- **showReloadPrompt:** function or boolean - set to a function that returns\n  a Promise that resolves when user agrees to reload, or rejects if \n  the user dismisses. set to `true` if you simply want to rely on the default implementation\n  that uses `window.confirm`, or to `false` if you want to skip waiting and claim clients.\n  - defaults to `false`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcansin%2Fnext-with-offline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcansin%2Fnext-with-offline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcansin%2Fnext-with-offline/lists"}