๐ Modular ServiceWorker: stream to response, CDN-like local cache.
Source of the name here (Shade + Winter Maple).
- Serve
ReadableStreams under an ephemeral path, reachable viaGETrequests. - A local cache that functions like a CDN.
- AppCache respun.
swReq.js: Service worker for local share handling and stream-to-response conversion, as well as an AppCache manifest-driven prefetch cache (onlyCACHE:gets used, 304 checks every time). Everything else not covered gets bypassed.swCdn.js: The above, plus the full local CDN.swLru.js: TheSharedWorkerfor cleaning up local CDN caches. Not needed byswReq.js.shade.mjs: A set of APIs used by pages to receive shares, register and manage streams, as well as supplying AppCache manifests. Also used to stream warnings and errors back to the page console.
- Hit browser's own HTTP cache as much as possible.
- One incoming request, at most one outgoing request.
- A copy of paths should be available in RAM as compressed trie.
@/maple-file/<rdnn>?to=<targetUrl>:Handle PWA file opens locally(removed).@/maple-share/<rdnn>?name=&desc=&from=: Handle PWA shares locally.<rdnn>: ID in reverse domain name notation, registered by pages. Having this causes the page to redirect to the registered page when it's not open. The ServiceWorker will hand the files over to the target page.
@/maple-stream/<streamId>:ReadableStreamas aGETresponse, single-use by default.HEADrequests before the finalGETdo not cause expiration. Uses theRangeheader withbytesmembers instead of URL parameters, howeverstart=andsize=can be used. Defaults toapplication/octet-stream.@/maple-blob/<blobId>: Reusable version ofmaple-stream, which causesReadableStreamto be funneled into cache. Reusable blobs will all be deleted after 900 seconds of creation, and they can be manually destroyed by their creators.
- Shaded Maple and its request interception capability (local stream, local blob, local share, local CDN) will not kick in until it is ready.
- There's no intention for Shaded Maple to be a plugin of a toolchain, as the SW part is designed to be mostly drop-and-forget.
- Anyone is welcome to build their own toolchain to generate the AppCache manifest file. Should be much simpler than most toolchains are offering on their own.
- Most requests, will be sent to the server nonetheless to check for 304, unless Shaded Maple determines that the device is fully offline. Requests that normally don't expect many changes have different rules.
- All responses will have a
Dateheader written whenever not set. - Browser cache maybe prioritised over Shaded Maple by browsers themselves, so Shaded Maple itself may not cause an inflated network request count.
- Requests hitting local caches will still be served first, the 304 checks and updates are just run in the background.
- Requests and responses that don't typically change much will be bounded by a 5-second-minimum, 8-hour-maximum duration before 304 checks occur, customised through response headers.
- Being either stale or expired will cause the 304 check.
- Requests having
Sec-Fetch-Destbeing one of such values (e.g.image) apply. - Requests having
Acceptcontaining matching MIME (e.g.image/*,audio/*) apply.
- Requests that are not
GETorHEADbypasses caching entirely. - WebSocket and SSE bypasses caching entirely.
- Requests and responses may get affected by
Cache-Control.- Responses and caches having
immutablecauses 304 checks to not trigger entirely until expiration. - Requests having
no-cachebypasses local serving, but still stores. Responses and caches havingno-cachetriggers 304 checks on all requests. - Requests having
no-storeorno-transformbypasses local serving and storage. Responses and caches havingno-storeorno-transformdon't get stored. - Responses or caches having
privateandmust-understandare the same asno-storeto allow the browser itself to take over. - Responses or caches having
publicare having this directive ignored to allow default Shaded Maple behaviour. - Responses or caches having
stale-while-revalidatecauses 304 checks to happen when its specified stale duration is reached. Prioritized overmax-ageands-max-age. - Responses or caches having
s-max-agecauses 304 checks to happen when its specified expiration duration is reached. Prioritized overmax-age. - Requests having
max-ageandmax-stale, unless the value is0(same asno-cache), have their mentioned directives ignored for default behaviour. Responses or caches havingmax-agecauses 304 checks to happen when its specified expiration duration is reached. min-freshandstale-if-errorare ignored entirely for requests, as major browsers aren't seen sending or supporting them.- Responses or caches having
stale-if-errorscauses error responses to bypass storage, while attempt to serve a local cached version having no error status when available. only-if-cachedfor requests is ignored for default Shaded Maple behaviour.
- Responses and caches having
- All responses will have a
- AppCache manifests are not a requirement.
- They are registered by pages themselves on-demand.
- They just seed the local CDN, they aren't the final authority.
- They are exempt from caching entirely, by
text/text/cache-manifestor*.manifest. - Dynamic sites can use the
NETWORK:directives for SSR pages or API requests, if they don't useno-cache,no-storeorno-transform.
no-cacheandno-storeare respected:no-cachebypass triggering the cache serve entirely without preventing storage,no-storebypasses storing. Maybeno-transformwill also bypass Shaded Maple entirely, since Shaded Maple is transforming the request in some way.- Shaded Maple's service worker and/or pages may control a shared worker for background cache pruning.