How to develop ClojureScript in Web worker?

279 views
Skip to first unread message

Jiyin Yiyong

unread,
May 30, 2016, 11:58:37 PM5/30/16
to ClojureScript
As I can see the hot loading will fail in such case since it cannot touch the DOM. But it's a obvious solution we need to gain performance in a browser. Is there some solution for it now?

Eivind Magnus Hvidevold

unread,
May 31, 2016, 5:00:45 AM5/31/16
to clojur...@googlegroups.com

I am using a ClojureScript web worker in my game, see bootstrap script here:

--
Eivind Magnus Hvidevold
Cell: +47 92 678 423

On Tue, May 31, 2016 at 5:58 AM, Jiyin Yiyong <jiyin...@gmail.com> wrote:
As I can see the hot loading will fail in such case since it cannot touch the DOM. But it's a obvious solution we need to gain performance in a browser. Is there some solution for it now?

--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to the Google Groups "ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.

jiyinyiyong

unread,
May 31, 2016, 8:20:48 AM5/31/16
to clojur...@googlegroups.com
That's nice. So hot code loading will not work here right?

You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/4b7zPDh70_M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojurescrip...@googlegroups.com.

Eivind Magnus Hvidevold

unread,
May 31, 2016, 10:51:15 AM5/31/16
to clojur...@googlegroups.com

I don't think so. Figwheel gives an error when run from a worker: "Figwheel: Can't start Figwheel!! This browser doesn't support WebSockets".

When figwheel reloads the main page, I make it terminate and restart the worker.

--
Eivind Magnus Hvidevold
Cell: +47 92 678 423

jiyinyiyong

unread,
May 31, 2016, 10:55:36 AM5/31/16
to clojur...@googlegroups.com
Still thanks.

Alan Moore

unread,
Jun 1, 2016, 3:55:54 PM6/1/16
to ClojureScript
On Tuesday, May 31, 2016 at 7:51:15 AM UTC-7, Eivind Magnus Hvidevold wrote:
> I don't think so. Figwheel gives an error when run from a worker: "Figwheel: Can't start Figwheel!! This browser doesn't support WebSockets".

Firefox was the last browser to add support for websockets in webworkers (fixed in FF 38):

https://bugzilla.mozilla.org/show_bug.cgi?id=504553

So make sure you are using a recent browser.

Figwheel tests for websocket support by checking for the existence of window.WebSocket. However, webworkers cannot access the window object so this will always fail in a webworker. This doesn't mean that a webworker-aware Figwheel couldn't use "new WebWorker(...)" and check for an exception/error instead.

Regardless, I don't think you are going to get Figwheel working in a webworker *and* in the main thread at the same time. Maybe one or the other but not both due to conflicts on the server-side w.r.t. port numbers and the like. Also, there are likely other assumptions in Figwheel about access to the DOM/window that go beyond simply testing for websocket support... YMWV.

Good luck!

Alan

jiyinyiyong

unread,
Jun 1, 2016, 10:48:07 PM6/1/16
to ClojureScript
I'm on the boot-reload side and it is okey with different socket port numbers.Yeah, it's still tricky for boot-reload to both at the same time too.

Reply all
Reply to author
Forward
0 new messages