Fork me on GitHub
#shadow-cljs
<
2019-04-02
>
crankyadmin09:04:24

👋:skin-tone-2: I'm attempting to use a service worker to cache some files locally on the client machine.

crankyadmin09:04:06

; "main.js" is the name for the bundle entry
        :modules  {:main           {:entries [<snip>.]
                                    :init-fn <snip>.
                   :service-worker {:entries    [<snip>.viewer.service-worker]
                                    :depends-on #{:main}
                                    ;:web-worker true
                                    }}

crankyadmin09:04:41

But I keep getting `service-worker.js:1 Uncaught ReferenceError: SHADOW_ENV is not defined at service-worker.js:1` in the console in Chrome.

crankyadmin09:04:06

But I keep getting service-worker.js:1 Uncaught ReferenceError: SHADOW_ENV is not defined at service-worker.js:1 in the console in Chrome.

crankyadmin09:04:53

Could anyone possibly point me in the right direction?

thheller09:04:51

;:web-worker true this needs to be true, otherwise things aren't loadable in a worker env

crankyadmin09:04:24

Yep, tried that too... gives a different error, two secs and I'll grab that.

crankyadmin09:04:48

With :web-worker true I get uncaught ReferenceError: importScripts is not defined

thheller09:04:10

hmm do service workers not support that?

crankyadmin09:04:46

Looks like something is borked...

thheller09:04:47

not actually sure they ever did but I thought they did

thheller09:04:51

to be honest CLJS is complete overkill for service workers, something like https://developers.google.com/web/tools/workbox/ seems much more practical

crankyadmin09:04:42

I'm stumped....

thheller10:04:50

service workers are weird. do you maybe have one already running that didn't update correctly or so?

thheller10:04:13

check the service-worker.js. it should start with importScripts("main.js")

thheller10:04:39

you are missing a "shared" module in your build config

thheller10:04:54

the way you have it setup now your service worker will load the entire app as well

thheller10:04:44

:modules
{:shared
 {:entries []}
 
 :main
 {:init-fn <snip>.!
  :depends-on #{:shared}}
 
 :service-worker
 {:entries [<snip>.viewer.service-worker]
  :depends-on #{:shared}
  :web-worker true
  }}

crankyadmin10:04:17

Cool. Give me a sec and I'll give it a try.

thheller10:04:31

that won't affect the error you see though

thheller10:04:00

can't try this right now. you can open an issue and I'll look at it later

crankyadmin10:04:40

:thumbsup::skin-tone-2: Cheers pal