{"id":21614510,"url":"https://github.com/munaibh/pika-worker","last_synced_at":"2026-04-16T18:03:50.707Z","repository":{"id":92062678,"uuid":"217860526","full_name":"munaibh/pika-worker","owner":"munaibh","description":"A demo to illustrate a web workers advantages (mainly keeping UI interactive when executing heavy tasks/logic).","archived":false,"fork":false,"pushed_at":"2020-09-20T14:21:01.000Z","size":641,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T16:55:31.185Z","etag":null,"topics":["demos","javascript","webworkers"],"latest_commit_sha":null,"homepage":"https://munaibh.github.io/pika-worker/","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/munaibh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-27T13:39:31.000Z","updated_at":"2025-02-14T06:11:15.000Z","dependencies_parsed_at":"2023-05-21T18:30:36.949Z","dependency_job_id":null,"html_url":"https://github.com/munaibh/pika-worker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/munaibh/pika-worker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munaibh%2Fpika-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munaibh%2Fpika-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munaibh%2Fpika-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munaibh%2Fpika-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/munaibh","download_url":"https://codeload.github.com/munaibh/pika-worker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/munaibh%2Fpika-worker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272995556,"owners_count":25027957,"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","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["demos","javascript","webworkers"],"created_at":"2024-11-24T22:08:14.470Z","updated_at":"2026-04-16T18:03:50.678Z","avatar_url":"https://github.com/munaibh.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./images/pikachu.gif\" width=\"80\" alt=\"Logo\" /\u003e\n  \u003ch1 align=\"center\"\u003ePikaWorker\u003c/h1\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/github/issues/munaibh/PikaWorker\" alt=\"issues\"\u003e\n  \u003cimg src=\"https://img.shields.io/github/license/munaibh/PikaWorker.svg\" alt=\"license\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cb\u003eA demo to illustrate a web workers advantage (using Pikachu running as an example).\u003c/b\u003e\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\n## What is this?\n\nThis repo demos the advantages of using a web worker to solve the UI being clogged up, this results in a better overall experience as it keeps our apps interative whilst performing heavy computations. \n\n\u003cbr\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./images/demo.gif\" alt=\"Demo of Web Worker Pickachu Example\" width=\"500\"\u003e\u003cbr\u003e\n  \u003csub\u003e(Example taken from the codepen example, found \u003ca href=\"https://codepen.io/munaibh/pen/QXoJQB\"\u003ehere\u003c/a\u003e)\u003c/a\u003e\u003c/sub\u003e\n\u003c/p\u003e\n\u003cbr\u003e\n\n\n## An explanation.\n\n\u003e A way to solve \"jank\" on the web is to stop intensive tasks/calculations running on the main thread and instead run operations adjacent to the main thread. This results in the main thread being freed; it can now perform UI operations which result in the app remaining interactive.\n\n```javascript\n// index.js\nif(window.Worker) {\n\tconst myCoolWorker = new Worker('worker.js')\n\tmyCoolWorker.onMessage = e =\u003e console.log(`Message ${e.data}`)\n\tmyCoolWorker.postMessage(id)\n}\n```\n\nTo create a `worker` all we do is instantiate a new worker and point it to a worker file. Next, we set an `onmessage` handler which acts as our communications channel for it to chat to us. Lastly, we send a `postMessage`  to kick off the worker (we also send it some data, in this case an `id`).\n\n```javascript\n// worker.js\nonmessage = async function(e) {\n\tconst id = e.data\n\tconst response = await fetch(`/do/cool/stuff/${id}`)\n\tconst data = await response.json()\n\tself.postMessage(data);\n}\n```\n\nIn the worker itself we have an `onmessage` handler in which we are receiving the passed `id`  and we're doing a some arbitrary logic (in this case a fetch) and then passing the result back up. \n\nThe worker is useful as here we can offload a ton of logic (e.g. transformations that are computationally heavy). Doing this won't \"jank\" out our UIs and allows everything to remain interactive.\n\n\u003cbr\u003e\n\u003ch3 align=\"center\"\u003e\n  Pretty Cool! 🤙\n\u003c/h3\u003e\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmunaibh%2Fpika-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmunaibh%2Fpika-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmunaibh%2Fpika-worker/lists"}