@budarin/psw-plugin-opfs-serve-range 1.1.7 → 1.1.9
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/README.md +115 -123
- package/README.ru.md +101 -109
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -163,11 +163,11 @@ The response may not have a `Content-Length` header – when writing the full bo
|
|
|
163
163
|
|
|
164
164
|
Client‑side helpers are exported from the entry point `@budarin/psw-plugin-opfs-serve-range/client`. This section gives signatures, types, and examples; [opfs-cache-behavior.md](https://github.com/budarin/psw-plugin-opfs-serve-range/blob/master/docs/opfs-cache-behavior.md) only describes **when** the service worker sends messages (limits, LRU, eviction), not the API.
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
### Message payload
|
|
167
167
|
|
|
168
168
|
Each handler receives a `MessageEvent`; `event.data` is `{ type: string } & OpfsMessagePayload`, and some events add a `count` field. The package type `OpfsMessagePayload` is `{ url?: string; size?: number; limit?: number; reason?: string }`.
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
### Message subscriptions
|
|
171
171
|
|
|
172
172
|
Each function takes a handler and returns an unsubscribe function (call it to remove the subscription). Below are the subscriptions for messages that the service worker actually sends in the current version.
|
|
173
173
|
|
|
@@ -175,102 +175,94 @@ Each function takes a handler and returns an unsubscribe function (call it to re
|
|
|
175
175
|
type Unsubscribe = () => void;
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
- **`onOPFSQuotaExceeded`** — subscribe to notification when the browser throws QuotaExceeded while writing to OPFS.
|
|
179
179
|
|
|
180
|
-
```ts
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
```ts
|
|
181
|
+
type EventData = {
|
|
182
|
+
type: string;
|
|
183
|
+
url: string;
|
|
184
|
+
};
|
|
183
185
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
{
|
|
187
|
-
type: string;
|
|
188
|
-
url: string;
|
|
189
|
-
}
|
|
190
|
-
```
|
|
186
|
+
onOPFSQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
|
|
187
|
+
```
|
|
191
188
|
|
|
192
|
-
|
|
189
|
+
- **`onOPFSWriteSkipped`** — subscribe to notification when the write was skipped (file does not fit even after eviction).
|
|
193
190
|
|
|
194
|
-
```ts
|
|
195
|
-
|
|
196
|
-
|
|
191
|
+
```ts
|
|
192
|
+
type EventData = {
|
|
193
|
+
type: string;
|
|
194
|
+
url: string;
|
|
195
|
+
size: number; // File size in bytes
|
|
196
|
+
reason: string; // Reason the write was not started
|
|
197
|
+
};
|
|
197
198
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
{
|
|
201
|
-
type: string;
|
|
202
|
-
url: string;
|
|
203
|
-
/** File size in bytes */
|
|
204
|
-
size: number;
|
|
205
|
-
/** Reason the write was not started */
|
|
206
|
-
reason: string;
|
|
207
|
-
}
|
|
208
|
-
```
|
|
199
|
+
onOPFSWriteSkipped(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
|
|
200
|
+
```
|
|
209
201
|
|
|
210
|
-
|
|
202
|
+
- **`onOPFSEvictionCompleted`** — subscribe to notification when eviction has finished.
|
|
211
203
|
|
|
212
|
-
```ts
|
|
213
|
-
|
|
214
|
-
|
|
204
|
+
```ts
|
|
205
|
+
type EventData = {
|
|
206
|
+
type: string;
|
|
207
|
+
count: number; // Number of files removed by eviction
|
|
208
|
+
};
|
|
215
209
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
{
|
|
219
|
-
type: string;
|
|
220
|
-
/** Number of files removed by eviction */
|
|
221
|
-
count: number;
|
|
222
|
-
}
|
|
223
|
-
```
|
|
210
|
+
onOPFSEvictionCompleted(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
|
|
211
|
+
```
|
|
224
212
|
|
|
225
|
-
|
|
213
|
+
- **`onOPFSWriteFailed`** — subscribe to notification on write error (network, disk, partial file removed).
|
|
226
214
|
|
|
227
|
-
```ts
|
|
228
|
-
|
|
229
|
-
|
|
215
|
+
```ts
|
|
216
|
+
type EventData = {
|
|
217
|
+
type: string;
|
|
218
|
+
url?: string;
|
|
219
|
+
reason: string; // Reason the write failed
|
|
220
|
+
};
|
|
230
221
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
{
|
|
234
|
-
type: string;
|
|
235
|
-
url?: string;
|
|
236
|
-
/** Reason the write failed */
|
|
237
|
-
reason: string;
|
|
238
|
-
}
|
|
239
|
-
```
|
|
222
|
+
onOPFSWriteFailed(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
|
|
223
|
+
```
|
|
240
224
|
|
|
241
|
-
|
|
225
|
+
- **`onOPFSSkipQuotaExceeded`** — subscribe to notification on repeat request for a blacklisted URL (resource not cached).
|
|
242
226
|
|
|
243
|
-
```ts
|
|
244
|
-
|
|
245
|
-
|
|
227
|
+
```ts
|
|
228
|
+
type EventData = {
|
|
229
|
+
type: string;
|
|
230
|
+
url: string;
|
|
231
|
+
};
|
|
246
232
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
{
|
|
250
|
-
type: string;
|
|
251
|
-
url: string;
|
|
252
|
-
}
|
|
253
|
-
```
|
|
233
|
+
onOPFSSkipQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
|
|
234
|
+
```
|
|
254
235
|
|
|
255
|
-
|
|
236
|
+
### Cache management and types
|
|
256
237
|
|
|
257
|
-
|
|
238
|
+
- **`listOpfsCachedResources`** — returns the list of cached resources.
|
|
258
239
|
|
|
259
|
-
```ts
|
|
260
|
-
listOpfsCachedResources(): Promise<OpfsCachedResource[]>
|
|
261
|
-
```
|
|
240
|
+
```ts
|
|
241
|
+
listOpfsCachedResources(): Promise<OpfsCachedResource[]>
|
|
242
|
+
```
|
|
262
243
|
|
|
263
|
-
|
|
244
|
+
Each array element:
|
|
264
245
|
|
|
265
|
-
```ts
|
|
266
|
-
|
|
267
|
-
|
|
246
|
+
```ts
|
|
247
|
+
interface OpfsCachedResource {
|
|
248
|
+
url: string;
|
|
249
|
+
size: number;
|
|
250
|
+
type: string | undefined;
|
|
251
|
+
lastModified: string | undefined;
|
|
252
|
+
}
|
|
253
|
+
```
|
|
268
254
|
|
|
269
|
-
|
|
255
|
+
- **`hasInOpfsCache`** — checks whether a URL is in the cache.
|
|
270
256
|
|
|
271
|
-
```ts
|
|
272
|
-
|
|
273
|
-
```
|
|
257
|
+
```ts
|
|
258
|
+
hasInOpfsCache(url: string): Promise<boolean>
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
- **`deleteFromOpfsCache`** — removes a resource by URL from the cache.
|
|
262
|
+
|
|
263
|
+
```ts
|
|
264
|
+
deleteFromOpfsCache(url: string): Promise<void>
|
|
265
|
+
```
|
|
274
266
|
|
|
275
267
|
Types `OpfsMessagePayload` and `OpfsCachedResource` are exported. Message type constants (name equals the string value in `event.data.type`): `OPFS_MSG_QUOTA_EXCEEDED`, `OPFS_MSG_WRITE_SKIPPED_SIZE`, `OPFS_MSG_CACHE_LIMIT_REACHED`, `OPFS_MSG_EVICTION_COMPLETED`, `OPFS_MSG_WRITE_FAILED`, `OPFS_MSG_SKIP_QUOTA_EXCEEDED`.
|
|
276
268
|
|
|
@@ -312,52 +304,52 @@ If you need finer‑grained control (show a list of cached resources and let use
|
|
|
312
304
|
|
|
313
305
|
Global cache settings (folder name, quota fraction) are set in **configureOpfs({ folderName, maxCacheFraction })**. Below are the package plugins and their options.
|
|
314
306
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
```ts
|
|
318
|
-
opfsServeRange(options?: {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}): Plugin | undefined
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
```ts
|
|
330
|
-
opfsPrecache(options: {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}): Plugin | undefined
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
```ts
|
|
341
|
-
opfsRangeFromNetworkAndCache(options?: {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}): Plugin | undefined
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
```ts
|
|
353
|
-
opfsBackgroundFetch(options?: {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}): Plugin | undefined
|
|
360
|
-
```
|
|
307
|
+
- **`opfsServeRange`** — reads files from OPFS and serves requested byte ranges.
|
|
308
|
+
|
|
309
|
+
```ts
|
|
310
|
+
opfsServeRange(options?: {
|
|
311
|
+
order?: number;
|
|
312
|
+
enableLogging?: boolean;
|
|
313
|
+
include?: string[];
|
|
314
|
+
exclude?: string[];
|
|
315
|
+
rangeResponseCacheControl?: string; // Cache-Control for 206 responses (default: max-age=31536000, immutable)
|
|
316
|
+
}): Plugin | undefined
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
- **`opfsPrecache`** — during SW install, fetches a list of URLs and writes them to OPFS.
|
|
320
|
+
|
|
321
|
+
```ts
|
|
322
|
+
opfsPrecache(options: {
|
|
323
|
+
urls: string[] | (() => Promise<string[]>); // array of URLs or function
|
|
324
|
+
order?: number;
|
|
325
|
+
enableLogging?: boolean;
|
|
326
|
+
pinned?: string[]; // glob patterns for URLs protected from eviction (see «Pinned resources»)
|
|
327
|
+
}): Plugin | undefined
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
- **`opfsRangeFromNetworkAndCache`** — handles requests that opfsServeRange did not serve (resource not in cache yet): goes to the network, streams the response to the client, and optionally fills OPFS in the background.
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
opfsRangeFromNetworkAndCache(options?: {
|
|
334
|
+
order?: number;
|
|
335
|
+
include?: string[];
|
|
336
|
+
exclude?: string[];
|
|
337
|
+
enableLogging?: boolean;
|
|
338
|
+
pinned?: string[]; // glob patterns for URLs protected from eviction
|
|
339
|
+
}): Plugin | undefined
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
- **`opfsBackgroundFetch`** — on successful Background Fetch completion, writes responses into OPFS; subsequent Range requests for these URLs are served by opfsServeRange.
|
|
343
|
+
|
|
344
|
+
```ts
|
|
345
|
+
opfsBackgroundFetch(options?: {
|
|
346
|
+
order?: number;
|
|
347
|
+
include?: string[];
|
|
348
|
+
exclude?: string[];
|
|
349
|
+
enableLogging?: boolean;
|
|
350
|
+
pinned?: string[]; // glob patterns for URLs protected from eviction
|
|
351
|
+
}): Plugin | undefined
|
|
352
|
+
```
|
|
361
353
|
|
|
362
354
|
To trigger downloads from the client: `@budarin/pluggable-serviceworker/client/background-fetch`.
|
|
363
355
|
|
package/README.ru.md
CHANGED
|
@@ -153,11 +153,11 @@ await writeToOpfs(dir, key, response.body, metadata);
|
|
|
153
153
|
|
|
154
154
|
Клиентские хелперы экспортируются из entry point `@budarin/psw-plugin-opfs-serve-range/client`. В этом разделе — сигнатуры, типы и примеры; в [opfs-cache-behavior.ru.md](https://github.com/budarin/psw-plugin-opfs-serve-range/blob/master/docs/opfs-cache-behavior.ru.md) описано только **когда** сервис-воркер шлёт сообщения (лимиты, LRU, эвикция), не API.
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
### Данные в сообщениях
|
|
157
157
|
|
|
158
158
|
Обработчик получает `MessageEvent`; `event.data` имеет тип `{ type: string } & OpfsMessagePayload` плюс при необходимости поле `count`. Тип `OpfsMessagePayload` в пакете: `{ url?: string; size?: number; limit?: number; reason?: string }`.
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
### Подписки на сообщения
|
|
161
161
|
|
|
162
162
|
Каждая функция принимает обработчик и возвращает функцию отписки (вызов снимает подписку). Ниже перечислены подписки, сообщения которых сервис-воркер реально отправляет в текущей версии.
|
|
163
163
|
|
|
@@ -165,102 +165,94 @@ await writeToOpfs(dir, key, response.body, metadata);
|
|
|
165
165
|
type Unsubscribe = () => void;
|
|
166
166
|
```
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
- **`onOPFSQuotaExceeded`** — подписка на уведомление об исчерпании квоты при записи в OPFS.
|
|
169
169
|
|
|
170
|
-
```ts
|
|
171
|
-
onOPFSQuotaExceeded(handler: (event: MessageEvent) => void): Unsubscribe
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
- `event.data`:
|
|
175
170
|
```ts
|
|
176
|
-
{
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
```
|
|
171
|
+
type EventData = {
|
|
172
|
+
type: string;
|
|
173
|
+
url: string;
|
|
174
|
+
};
|
|
181
175
|
|
|
182
|
-
|
|
176
|
+
onOPFSQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
|
|
177
|
+
```
|
|
183
178
|
|
|
184
|
-
|
|
185
|
-
onOPFSWriteSkipped(handler: (event: MessageEvent) => void): Unsubscribe
|
|
186
|
-
```
|
|
179
|
+
- **`onOPFSWriteSkipped`** — подписка на уведомление о пропуске записи (файл не влезает даже после эвикции).
|
|
187
180
|
|
|
188
|
-
- `event.data`:
|
|
189
181
|
```ts
|
|
190
|
-
{
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
reason: string;
|
|
197
|
-
}
|
|
198
|
-
```
|
|
182
|
+
type EventData = {
|
|
183
|
+
type: string;
|
|
184
|
+
url: string;
|
|
185
|
+
size: number; // Размер файла в байтах
|
|
186
|
+
reason: string; // Причина (почему запись не начата)
|
|
187
|
+
};
|
|
199
188
|
|
|
200
|
-
|
|
189
|
+
onOPFSWriteSkipped(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
|
|
190
|
+
```
|
|
201
191
|
|
|
202
|
-
|
|
203
|
-
onOPFSEvictionCompleted(handler: (event: MessageEvent) => void): Unsubscribe
|
|
204
|
-
```
|
|
192
|
+
- **`onOPFSEvictionCompleted`** — подписка на уведомление о завершении эвикции.
|
|
205
193
|
|
|
206
|
-
- `event.data`:
|
|
207
194
|
```ts
|
|
208
|
-
{
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
```
|
|
195
|
+
type EventData = {
|
|
196
|
+
type: string;
|
|
197
|
+
count: number; // Число удалённых при эвикции файлов
|
|
198
|
+
};
|
|
214
199
|
|
|
215
|
-
|
|
200
|
+
onOPFSEvictionCompleted(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
|
|
201
|
+
```
|
|
216
202
|
|
|
217
|
-
|
|
218
|
-
onOPFSWriteFailed(handler: (event: MessageEvent) => void): Unsubscribe
|
|
219
|
-
```
|
|
203
|
+
- **`onOPFSWriteFailed`** — подписка на уведомление об ошибке записи (сеть, диск, удалён частичный файл).
|
|
220
204
|
|
|
221
|
-
- `event.data`:
|
|
222
205
|
```ts
|
|
223
|
-
{
|
|
206
|
+
type EventData = {
|
|
224
207
|
type: string;
|
|
225
208
|
url?: string;
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
209
|
+
reason: string; // Причина ошибки записи
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
onOPFSWriteFailed(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
|
|
229
213
|
```
|
|
230
214
|
|
|
231
|
-
|
|
215
|
+
- **`onOPFSSkipQuotaExceeded`** — подписка на уведомление о повторном запросе к URL из чёрного списка (ресурс не кешируем).
|
|
232
216
|
|
|
233
|
-
```ts
|
|
234
|
-
onOPFSSkipQuotaExceeded(handler: (event: MessageEvent) => void): Unsubscribe
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
- `event.data`:
|
|
238
217
|
```ts
|
|
239
|
-
{
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
218
|
+
type EventData = {
|
|
219
|
+
type: string;
|
|
220
|
+
url: string;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
onOPFSSkipQuotaExceeded(handler: (event: MessageEvent<EventData>) => void): Unsubscribe
|
|
243
224
|
```
|
|
244
225
|
|
|
245
|
-
|
|
226
|
+
### Управление кешем и типы
|
|
246
227
|
|
|
247
|
-
|
|
228
|
+
- **`listOpfsCachedResources`** — возвращает список закешированных ресурсов.
|
|
248
229
|
|
|
249
|
-
```ts
|
|
250
|
-
listOpfsCachedResources(): Promise<OpfsCachedResource[]>
|
|
251
|
-
```
|
|
230
|
+
```ts
|
|
231
|
+
listOpfsCachedResources(): Promise<OpfsCachedResource[]>
|
|
232
|
+
```
|
|
252
233
|
|
|
253
|
-
|
|
234
|
+
Элемент массива:
|
|
254
235
|
|
|
255
|
-
```ts
|
|
256
|
-
|
|
257
|
-
|
|
236
|
+
```ts
|
|
237
|
+
interface OpfsCachedResource {
|
|
238
|
+
url: string;
|
|
239
|
+
size: number;
|
|
240
|
+
type: string | undefined;
|
|
241
|
+
lastModified: string | undefined;
|
|
242
|
+
}
|
|
243
|
+
```
|
|
258
244
|
|
|
259
|
-
|
|
245
|
+
- **`hasInOpfsCache`** — проверяет наличие URL в кеше.
|
|
260
246
|
|
|
261
|
-
```ts
|
|
262
|
-
|
|
263
|
-
```
|
|
247
|
+
```ts
|
|
248
|
+
hasInOpfsCache(url: string): Promise<boolean>
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
- **`deleteFromOpfsCache`** — удаляет ресурс по URL из кеша.
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
deleteFromOpfsCache(url: string): Promise<void>
|
|
255
|
+
```
|
|
264
256
|
|
|
265
257
|
Типы `OpfsMessagePayload` и `OpfsCachedResource` экспортируются из пакета. Константы типов сообщений (имя совпадает со строковым значением в `event.data.type`): `OPFS_MSG_QUOTA_EXCEEDED`, `OPFS_MSG_WRITE_SKIPPED_SIZE`, `OPFS_MSG_CACHE_LIMIT_REACHED`, `OPFS_MSG_EVICTION_COMPLETED`, `OPFS_MSG_WRITE_FAILED`, `OPFS_MSG_SKIP_QUOTA_EXCEEDED`.
|
|
266
258
|
|
|
@@ -302,52 +294,52 @@ const unsubSkip = onOPFSSkipQuotaExceeded((event: MessageEvent) => {
|
|
|
302
294
|
|
|
303
295
|
Общая настройка кеша (имя папки, доля квоты) задаётся в **configureOpfs({ folderName, maxCacheFraction })**. Ниже — плагины пакета и их опции.
|
|
304
296
|
|
|
305
|
-
|
|
297
|
+
- **`opfsServeRange`** — читает файлы из OPFS и отдаёт запрошенные диапазоны байтов.
|
|
306
298
|
|
|
307
|
-
```ts
|
|
308
|
-
opfsServeRange(options?: {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}): Plugin | undefined
|
|
315
|
-
```
|
|
299
|
+
```ts
|
|
300
|
+
opfsServeRange(options?: {
|
|
301
|
+
order?: number;
|
|
302
|
+
enableLogging?: boolean;
|
|
303
|
+
include?: string[];
|
|
304
|
+
exclude?: string[];
|
|
305
|
+
rangeResponseCacheControl?: string; // Cache-Control для ответов 206 (по умолчанию max-age=31536000, immutable)
|
|
306
|
+
}): Plugin | undefined
|
|
307
|
+
```
|
|
316
308
|
|
|
317
|
-
|
|
309
|
+
- **`opfsPrecache`** — при установке сервис-воркера загружает список URL и записывает их в OPFS.
|
|
318
310
|
|
|
319
|
-
```ts
|
|
320
|
-
opfsPrecache(options: {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}): Plugin | undefined
|
|
326
|
-
```
|
|
311
|
+
```ts
|
|
312
|
+
opfsPrecache(options: {
|
|
313
|
+
urls: string[] | (() => Promise<string[]>); // список URL или функция
|
|
314
|
+
order?: number;
|
|
315
|
+
enableLogging?: boolean;
|
|
316
|
+
pinned?: string[]; // glob-паттерны URL, защищённых от эвикции (см. «Закреплённые ресурсы»)
|
|
317
|
+
}): Plugin | undefined
|
|
318
|
+
```
|
|
327
319
|
|
|
328
|
-
|
|
320
|
+
- **`opfsRangeFromNetworkAndCache`** — обрабатывает запросы, которые opfsServeRange не обслужил (ресурс ещё не в кеше): идёт в сеть, отдаёт ответ клиенту и при необходимости догружает файл в OPFS в фоне.
|
|
329
321
|
|
|
330
|
-
```ts
|
|
331
|
-
opfsRangeFromNetworkAndCache(options?: {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}): Plugin | undefined
|
|
338
|
-
```
|
|
322
|
+
```ts
|
|
323
|
+
opfsRangeFromNetworkAndCache(options?: {
|
|
324
|
+
order?: number;
|
|
325
|
+
include?: string[];
|
|
326
|
+
exclude?: string[];
|
|
327
|
+
enableLogging?: boolean;
|
|
328
|
+
pinned?: string[]; // glob-паттерны URL, защищённых от эвикции
|
|
329
|
+
}): Plugin | undefined
|
|
330
|
+
```
|
|
339
331
|
|
|
340
|
-
|
|
332
|
+
- **`opfsBackgroundFetch`** — при успешном завершении загрузки через Background Fetch API записывает ответы в OPFS; дальнейшие range‑запросы по этим URL обслуживает opfsServeRange.
|
|
341
333
|
|
|
342
|
-
```ts
|
|
343
|
-
opfsBackgroundFetch(options?: {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}): Plugin | undefined
|
|
350
|
-
```
|
|
334
|
+
```ts
|
|
335
|
+
opfsBackgroundFetch(options?: {
|
|
336
|
+
order?: number;
|
|
337
|
+
include?: string[];
|
|
338
|
+
exclude?: string[];
|
|
339
|
+
enableLogging?: boolean;
|
|
340
|
+
pinned?: string[]; // glob-паттерны URL, защищённых от эвикции
|
|
341
|
+
}): Plugin | undefined
|
|
342
|
+
```
|
|
351
343
|
|
|
352
344
|
Запуск загрузки с клиента: утилиты из `@budarin/pluggable-serviceworker/client/background-fetch`.
|
|
353
345
|
|