offline-page-kit 0.2.1 โ†’ 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
File without changes
package/README.md ADDED
@@ -0,0 +1,313 @@
1
+ <!-- =============================================== -->
2
+ <!-- ๐Ÿ”ฅ Animated SVG Header Banner -->
3
+ <!-- =============================================== -->
4
+
5
+ <p align="center">
6
+ <img src="https://capsule-render.vercel.app/api?type=waving&color=ff7a00&height=200&section=header&text=offline-page-kit&fontSize=42&fontColor=ffffff&animation=fadeIn&fontAlignY=38" />
7
+ </p>
8
+
9
+ <p align="center">
10
+ <b>Framework-agnostic Offline Fallback System</b><br/>
11
+ Lightweight โ€ข Deterministic โ€ข Production-Safe
12
+ </p>
13
+
14
+ ---
15
+
16
+ <!-- =============================================== -->
17
+ <!-- ๐ŸŒ Social & Community Links -->
18
+ <!-- =============================================== -->
19
+
20
+ <p align="center">
21
+ ๐ŸŒ <b>Website:</b> <a href="https://devcrack.dev">devcrack.dev</a> &nbsp; | &nbsp;
22
+ โ–ถ๏ธ <b>YouTube:</b> <a href="https://www.youtube.com/@dev-crack">DevCrack Channel</a><br/>
23
+ ๐Ÿ”น <b>Facebook:</b> <a href="https://web.facebook.com/profile.php?id=61573018852861">Profile</a> &nbsp; | &nbsp;
24
+ ๐Ÿ”น <b>Community Group:</b> <a href="https://web.facebook.com/groups/1672263410026163">Join Community</a>
25
+ </p>
26
+
27
+ ---
28
+
29
+ <!-- =============================================== -->
30
+ <!-- ๐ŸŸข NPM + CI + Coverage Badges -->
31
+ <!-- =============================================== -->
32
+
33
+ <p align="center">
34
+ <a href="https://www.npmjs.com/package/offline-page-kit">
35
+ <img src="https://img.shields.io/npm/v/offline-page-kit?style=for-the-badge&color=orange" alt="npm version">
36
+ </a>
37
+ <a href="https://www.npmjs.com/package/offline-page-kit">
38
+ <img src="https://img.shields.io/npm/dm/offline-page-kit?style=for-the-badge&color=blue" alt="npm downloads">
39
+ </a>
40
+ <a href="https://bundlephobia.com/package/offline-page-kit">
41
+ <img src="https://img.shields.io/bundlephobia/minzip/offline-page-kit?style=for-the-badge&color=purple" alt="bundle size">
42
+ </a>
43
+ <img src="https://img.shields.io/github/actions/workflow/status/kuhelahmed2024/offline-page-kit/ci.yml?style=for-the-badge" alt="CI status">
44
+ <img src="https://img.shields.io/codecov/c/github/kuhelahmed2024/offline-page-kit?style=for-the-badge" alt="coverage">
45
+ <img src="https://img.shields.io/badge/TypeScript-Ready-3178c6?style=for-the-badge&logo=typescript&logoColor=white" alt="TypeScript Ready">
46
+ <img src="https://img.shields.io/badge/Zero-Dependencies-black?style=for-the-badge" alt="Zero Dependencies">
47
+ </p>
48
+
49
+ ---
50
+
51
+ # ๐Ÿ“ฆ offline-page-kit
52
+
53
+ > Minimal, framework-agnostic Service Worker generator that prevents blank screens during network failure.
54
+
55
+ ---
56
+
57
+ # ๐ŸŸก Professional npm Description
58
+
59
+ **offline-page-kit** is a lightweight, zero-dependency Service Worker toolkit that provides deterministic offline fallback behavior for modern web applications.
60
+
61
+ It guarantees that when network connectivity fails, users see a controlled offline experience instead of browser error pages or blank screens.
62
+
63
+ Designed for production-grade stability across:
64
+
65
+ - Next.js
66
+ - Vite
67
+ - React
68
+ - Vue
69
+ - Static sites
70
+ - Any public-folder architecture
71
+
72
+ No Workbox.
73
+ No complex runtime caching layers.
74
+ No unpredictable asset behavior.
75
+
76
+ Just reliable navigation fallback.
77
+
78
+ ---
79
+
80
+ # ๐Ÿš€ Quick Start
81
+
82
+ ### 1๏ธโƒฃ Install
83
+
84
+ ```
85
+ npm install offline-page-kit
86
+ ```
87
+
88
+ ### 2๏ธโƒฃ Generate Service Worker
89
+
90
+ ```
91
+ npx offline-page-kit init --outDir public
92
+ ```
93
+
94
+ This generates:
95
+
96
+ ```
97
+ public/
98
+ โ”œโ”€โ”€ sw.js
99
+ โ”œโ”€โ”€ offline.html
100
+ โ””โ”€โ”€ offline.svg
101
+ ```
102
+
103
+ ### 3๏ธโƒฃ Register in Client
104
+
105
+ ```ts
106
+ import { registerOfflineKit } from "offline-page-kit";
107
+
108
+ registerOfflineKit({ debug: true });
109
+ ```
110
+
111
+ Done โœ…
112
+
113
+ ---
114
+
115
+ # ๐Ÿง  Architecture
116
+
117
+ ```
118
+ Browser
119
+ โ†“
120
+ Service Worker
121
+ โ†“
122
+ Fetch Navigation Request
123
+ โ”œโ”€ Network OK โ†’ return live page
124
+ โ””โ”€ Network FAIL โ†’ return cached offline.html
125
+ ```
126
+
127
+ Only navigation requests are intercepted.
128
+
129
+ No API mutation.
130
+ No asset rewriting.
131
+ No hidden caching layers.
132
+
133
+ ---
134
+
135
+ # ๐Ÿ”„ Lifecycle
136
+
137
+ ```
138
+ Install โ†’ Activate โ†’ Control โ†’ Fetch
139
+ ```
140
+
141
+ ### Install
142
+ - Caches offline page + fallback image
143
+ - Uses Promise.allSettled() to avoid failure
144
+
145
+ ### Activate
146
+ - Immediately claims clients
147
+
148
+ ### Fetch
149
+ - Applies network-first
150
+ - Falls back to offline page
151
+
152
+ ---
153
+
154
+ # ๐Ÿงฉ Framework Examples
155
+
156
+ ## Next.js (App Router)
157
+
158
+ ```tsx
159
+
160
+ // #/utils/SWRegister.tsx
161
+ "use client";
162
+
163
+ import { useEffect } from "react";
164
+ import { registerOfflineKit } from "offline-page-kit";
165
+
166
+ export default function SWRegister() {
167
+ useEffect(() => {
168
+ registerOfflineKit({ debug: true });
169
+ }, []);
170
+ return null;
171
+ }
172
+
173
+
174
+
175
+ // Root layout
176
+ import SWRegister from "@/utils/SWRegister";
177
+
178
+ // ...
179
+
180
+ export default function RootLayout({
181
+ children,
182
+ }: Readonly<{
183
+ children: React.ReactNode;
184
+ }>) {
185
+ return (
186
+ <html lang="en">
187
+ <body
188
+ className={`${geistSans.variable} ${geistMono.variable} antialiased`}
189
+ >
190
+ {children}
191
+ <SWRegister />
192
+ </body>
193
+ </html>
194
+ );
195
+ }
196
+
197
+ ```
198
+
199
+ ---
200
+
201
+ ## Vite / React
202
+
203
+ ```ts
204
+ import { registerOfflineKit } from "offline-page-kit";
205
+
206
+ registerOfflineKit();
207
+ ```
208
+
209
+ ---
210
+
211
+ # โš™ Windows PowerShell (VSCode)
212
+
213
+ ```
214
+ npx offline-page-kit init `
215
+ --outDir public `
216
+ --offlinePage /offline.html `
217
+ --offlineImage /offline.svg `
218
+ --cacheName my-app-cache-v1
219
+ ```
220
+ ---
221
+
222
+ # ๐Ÿ”นโš™ Windows CMD
223
+
224
+ ```
225
+ npx offline-page-kit init ^
226
+ --outDir public ^
227
+ --offlinePage /offline.html ^
228
+ --offlineImage /offline.svg ^
229
+ --cacheName my-app-cache-v1
230
+ ```
231
+ ---
232
+
233
+ # โš™ Linux/macOS (Bash/Zsh)
234
+
235
+ ```
236
+ npx offline-page-kit init \
237
+ --outDir public \
238
+ --offlinePage /offline.html \
239
+ --offlineImage /offline.svg \
240
+ --cacheName my-app-cache-v1
241
+ ```
242
+
243
+ | Option | Default | Description |
244
+ |--------|---------|------------|
245
+ | outDir | public | Static folder |
246
+ | offlinePage | /offline.html | Navigation fallback |
247
+ | offlineImage | /offline.svg | Fallback asset |
248
+ | cacheName | offline-page-kit | Cache namespace |
249
+
250
+ ---
251
+
252
+ # ๐Ÿ” Security
253
+
254
+ - Requires HTTPS (or localhost)
255
+ - Does not cache authenticated APIs
256
+ - Does not alter CORS behavior
257
+ - Per-origin scoped
258
+
259
+ ---
260
+
261
+ # โšก Performance
262
+
263
+ - Zero runtime dependencies
264
+ - Minimal memory usage
265
+ - No background sync
266
+ - No bundle overhead
267
+
268
+ ---
269
+
270
+ # ๐Ÿงช Testing
271
+
272
+ 1. Load site
273
+ 2. Reload once
274
+ 3. DevTools โ†’ Application โ†’ Service Workers
275
+ 4. Enable Offline
276
+ 5. Refresh
277
+
278
+ Offline page should render.
279
+
280
+ ---
281
+
282
+ # ๐Ÿข Production Notes
283
+
284
+ - Always deploy over HTTPS
285
+ - Version cache when updating logic
286
+ - Avoid multiple SWs in same scope
287
+
288
+ ---
289
+
290
+ # ๐Ÿงญ Roadmap
291
+
292
+ - Asset caching layer
293
+ - API strategy module
294
+ - Auto public folder scan
295
+ - Cache version hashing
296
+ - Metrics integration
297
+ - Advanced fallback strategies
298
+
299
+ ---
300
+
301
+ # ๐Ÿ“œ License
302
+
303
+ MIT
304
+
305
+ ---
306
+
307
+ <p align="center">
308
+ Built for modern web applications.
309
+ </p>
310
+
311
+ <p align="center">
312
+ <img src="https://capsule-render.vercel.app/api?type=waving&color=ff7a00&height=120&section=footer"/>
313
+ </p>