{"id":15387115,"url":"https://github.com/wildhoney/freelancer","last_synced_at":"2025-08-20T22:23:58.742Z","repository":{"id":57241590,"uuid":"83443357","full_name":"Wildhoney/Freelancer","owner":"Wildhoney","description":":necktie: An implementation of on-the-fly defined WebWorkers that are created inline using data URIs, rather than separate physical files — for the benefit of all humanity.","archived":false,"fork":false,"pushed_at":"2017-03-07T08:36:45.000Z","size":1972,"stargazers_count":67,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T00:12:47.799Z","etag":null,"topics":["concurrency","concurrent","sharedworker","webworker","webworkers"],"latest_commit_sha":null,"homepage":"https://freelancer-app.herokuapp.com/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Wildhoney.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-28T14:42:01.000Z","updated_at":"2024-07-23T14:43:16.000Z","dependencies_parsed_at":"2022-09-07T23:13:24.374Z","dependency_job_id":null,"html_url":"https://github.com/Wildhoney/Freelancer","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wildhoney%2FFreelancer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wildhoney%2FFreelancer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wildhoney%2FFreelancer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wildhoney%2FFreelancer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Wildhoney","download_url":"https://codeload.github.com/Wildhoney/Freelancer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249118780,"owners_count":21215618,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["concurrency","concurrent","sharedworker","webworker","webworkers"],"created_at":"2024-10-01T14:52:02.788Z","updated_at":"2025-04-15T17:32:07.378Z","avatar_url":"https://github.com/Wildhoney.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Freelancer](media/logo.png)\n\n\u003e `npm i freelancer --save`\u003cbr /\u003e\u003cbr /\u003e\n\u003e An implementation of on-the-fly defined WebWorkers that are created inline using data URIs, rather than separate physical files \u0026mdash; for the benefit of all humanity.\u003cbr /\u003e\u003cbr /\u003e\n\u003e **example:** [heroku](https://freelancer-app.herokuapp.com/) \u0026nbsp;\u0026nbsp;\u0026bull;\u0026nbsp;\u0026nbsp; ~500 bytes gzipped.\n\n![Travis](http://img.shields.io/travis/Wildhoney/Freelancer.svg?style=flat-square)\n\u0026nbsp;\n![npm](http://img.shields.io/npm/v/freelancer.svg?style=flat-square)\n\u0026nbsp;\n![License MIT](http://img.shields.io/badge/license-gpl3-lightgrey.svg?style=flat-square)\n\n## Getting Started\n\n`Freelancer` uses the **same** interface as `Worker` except the passed parameters upon instantiation are *slightly* different.\n\nNormally when invoking `new Worker` you pass the location of the file, whereas with `new Freelancer` you pass a function that contains the body of the worker.\n\n`Freelancer` also allows an *optional* [second parameter](#passing-parameters) to be passed that allows you to send additional options to the worker.\n\n```javascript\nimport { Freelancer } from 'freelancer';\n\nconst worker = new Freelancer(() =\u003e {\n   \n    self.addEventListener('message', event =\u003e {\n        console.log(event.data);\n        self.postMessage('Pong!');\n    });\n    \n});\n\nworker.addEventListener('message', event =\u003e console.log(event.data));\nworker.postMessage('Ping?');\n```\n\nIt's worth bearing in mind that the worker is still a separate thread and thus the typical [rules of closures](https://developer.mozilla.org/en/docs/Web/JavaScript/Closures) no longer apply \u0026ndash; any parameters you would like to be received by the worker would need to be sent using `postMessage` or by [passing parameters](#passing-parameters) upon instantiation.\n\n## Passing Parameters\n\nUpon instantiation of `Freelancer` you can use the second parameter to pass options that will be pushed to the worker \u0026ndash; passed options will be serialized using `JSON.stringify` and thus any data sent needs to be serializable \u0026ndash; which essentially means you're unable to pass by reference, and circular references will cause issues.\n\n```javascript\nimport { SharedFreelancer } from 'freelancer';\n\nconst options = { send: 'Ping?', respond: 'Pong!' };\n\nconst worker = new SharedFreelancer(options =\u003e {\n   \n    self.addEventListener('message', event =\u003e {\n        console.log(event.data);\n        self.postMessage(options.respond);\n    });\n    \n}, options);\n\nworker.addEventListener('message', event =\u003e console.log(event.data));\nworker.postMessage(options.send);\n```\n\nAlthough we refer to it as the *second parameter* you are in fact able to pass an infinite amount of parameters to the worker \u0026ndash; the only requirement is that the first parameter is the worker's function.\n\n## Dynamic Imports\n\nWhen defining a worker inline you'll lose the ability to `import` because the declaration needs to be at the top-level \u0026ndash; instead you should prefer [dynamic `import`s](https://github.com/tc39/proposal-dynamic-import) using `async` functions or a simple `Promise.then`.\n\n```javascript\nimport { Freelancer } from 'freelancer';\nimport translate from './translator';\n\nconst worker = new Freelancer(async () =\u003e {\n   \n    const translate = await import('./translator');\n    \n    self.addEventListener('message', event =\u003e {\n        self.postMessage(translate(options.respond));\n    });\n    \n});\n\nworker.postMessage(translate(options.send));\n```\n\n## Unsupported Worker\n\nIn some cases `SharedWorker` \u0026mdash; or to a lesser extent `Worker` \u0026mdash; may be `undefined` due to a lack of browser support ([see issue](https://github.com/Wildhoney/Freelancer/issues/2)). When a worker is unsupported you'll receive an error message, and thus it's crucial to [determine browser support](http://caniuse.com/#feat=sharedworkers) before using a particular worker.\n\n[![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](http://forthebadge.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwildhoney%2Ffreelancer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwildhoney%2Ffreelancer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwildhoney%2Ffreelancer/lists"}