The only example I can find for using a web worker with WebSharper is this old demo:

https://bitbucket.org/IntelliFactory/websharper.demos.webworker/src/53a08c18e9f9e62ba494fb154f05751738d26986/websharper.demos.webworker/Client.fs?at=default&fileviewer=file-view-default

With a single page application this appears to work, because all the JavaScript required is put into a single js file. But with my regular application, feeding the js file of the current project to the web worker fails because there are dependencies on other js files, including WebSharper.Core.JavaScript/Runtime.js.

  • github

    Having explicit support for targeting a web worker from WebSharper would be useful. What I'm currently trialing in WebSharper 4.x/Zafir is:

    Configure projects as libraries Set

    1
    
    <WebProjectOutputDir>Content</WebProjectOutputDir>

    (previously this was <WebSharperProject>Bundle</WebSharperProject>)

    that outputs everything into \Content\Scripts\WebSharper

    You can then manually determine the libaries you need and import them (and bundle as desired):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
        importScripts("build/WebSharper.Core.JavaScript/Runtime.js");
        importScripts("build/WebSharper.Main.js");
        importScripts("build/WebSharper.Collections.js");
        importScripts("build/WebSharper.Web.js");
    
        importScripts("build/ourlibrary.js");
        importScripts("build/anotherlibary.js");
        importScripts("build/yetmorelibary.js");
        importScripts("build/ourapp.js");

    Hope this helps, having something like this route documented would be really useful! In WebSharper 3.x this was a bit easier as you can get everything in concatenated form.