Document service worker usage.
This commit is contained in:
parent
f65ba9d853
commit
7a89ee6e1e
|
@ -29,6 +29,10 @@ babashka or Clojure JVM):
|
|||
|
||||
See [doc/nrepl](doc/nrepl).
|
||||
|
||||
### Service worker
|
||||
|
||||
See [doc/serviceworker.md](doc/serviceworker.md).
|
||||
|
||||
## Tasks
|
||||
|
||||
Run `bb tasks` to see all available tasks:
|
||||
|
|
26
doc/serviceworker.md
Normal file
26
doc/serviceworker.md
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Scittle in a service worker
|
||||
|
||||
You can use Scittle to bootstrap a ClojureScript based service worker.
|
||||
|
||||
Put the following code into e.g. `scittle-sw.js` to create a JavaScript based service worker, load Scittle, then fetch your script and eval it.
|
||||
|
||||
```javascript
|
||||
importScripts("scittle.min.js");
|
||||
|
||||
const request = await fetch("sw.cljs");
|
||||
const text = await request.text();
|
||||
const result = scittle.core.eval_string(text);
|
||||
```
|
||||
|
||||
Then load `scittle-sw.js` in your HTML:
|
||||
|
||||
```html
|
||||
<script>
|
||||
if('serviceWorker' in navigator)
|
||||
navigator.serviceWorker.register('scittle-sw.js');
|
||||
</script>
|
||||
```
|
||||
|
||||
This will load `sw.cljs` and eval it in the context of the service worker.
|
||||
|
||||
A ready-made example can be found at [chr15m/scittle-template-serviceworker](https://github.com/chr15m/scittle-template-serviceworker).
|
Loading…
Reference in a new issue