{"id":17760629,"url":"https://github.com/mbasso/script-wasm","last_synced_at":"2025-07-27T22:34:28.323Z","repository":{"id":109653404,"uuid":"184141108","full_name":"mbasso/script-wasm","owner":"mbasso","description":"Require WebAssembly modules using script tag","archived":false,"fork":false,"pushed_at":"2019-05-01T16:40:15.000Z","size":10,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-28T03:49:59.461Z","etag":null,"topics":["service-worker","wasm","webassembly"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mbasso.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","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-04-29T20:40:53.000Z","updated_at":"2023-06-18T20:29:44.000Z","dependencies_parsed_at":"2023-04-09T00:06:05.410Z","dependency_job_id":null,"html_url":"https://github.com/mbasso/script-wasm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mbasso/script-wasm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbasso%2Fscript-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbasso%2Fscript-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbasso%2Fscript-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbasso%2Fscript-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbasso","download_url":"https://codeload.github.com/mbasso/script-wasm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbasso%2Fscript-wasm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267436663,"owners_count":24086898,"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-07-27T02:00:11.917Z","response_time":82,"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":["service-worker","wasm","webassembly"],"created_at":"2024-10-26T19:06:55.165Z","updated_at":"2025-07-27T22:34:28.314Z","avatar_url":"https://github.com/mbasso.png","language":"JavaScript","funding_links":["https://paypal.me/BassoMatteo"],"categories":[],"sub_categories":[],"readme":"# script-wasm\n\n[![Build Status](https://travis-ci.org/mbasso/script-wasm.svg?branch=master)](https://travis-ci.org/mbasso/script-wasm)\n[![npm version](https://img.shields.io/npm/v/script-wasm.svg)](https://www.npmjs.com/package/script-wasm)\n[![npm downloads](https://img.shields.io/npm/dm/script-wasm.svg?maxAge=2592000)](https://www.npmjs.com/package/script-wasm)\n[![MIT](https://img.shields.io/npm/l/script-wasm.svg)](https://github.com/mbasso/script-wasm/blob/master/LICENSE.md)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/BassoMatteo)\n\n\u003e Require WebAssembly modules using script tag\n\n## Installation\n\nYou can install script-wasm using [npm](https://www.npmjs.com/package/script-wasm):\n\n```bash\nnpm install --save script-wasm\n```\n\nIf you aren't using npm in your project, you can include scriptWasm using UMD build in the dist folder with `importScripts` in the serviceWorker.\n\n## Usage\n\nOnce you have installed script-wasm, supposing a CommonJS environment, in yuor serviceWorker you can import and use it in this way:\n\n```js\nimport fetchWasmScript from 'script-wasm';\n// if you prefer, you can import it using a CDN instead\n// self.importScripts('https://unpkg.com/script-wasm@0.1.1/dist/script-wasm.min.js')\n\nself.addEventListener('fetch', (event) =\u003e {\n  const newResponse = fetchWasmScript(event.request);\n  // using CND:\n  // const newResponse = scriptWasm.default(event.request)\n\n  // returns null if the given request is not a .wasm from a \u003cscript\u003e tag\n  if (newResponse !== null) {\n    event.respondWith(newResponse);\n  }\n});\n```\n\nIn your html file:\n\n```html\n\u003c!--\n  data-import represents the importObject passed to instantiate the module\n  check out: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate\n--\u003e\n\u003cscript src=\"/example.wasm\" data-import=\"{ imports: { log: console.log } }\"\u003e\u003c/script\u003e\n```\n\n`example.wasm` can be a file with an associated `.wat` like the following, it imports `log` and automatically runs the function `$main` after the instantiation, using the `start` instruction:\n\n```wat\n(module\n  (func $log (import \"imports\" \"log\") (param i32))\n\n  (func $main\n    (call $log\n      (i32.add\n        (i32.const 2)\n        (i32.const 5)\n      )\n    )\n  )\n\n  (start $main)\n)\n```\n\n\n## API\n\n```js\n// serviceWorker\nfetchWasmScript(request: Request): Response?\n\n// html\n\u003cscript src=\"your_wasm_file.wasm\" data-import=\"your_import_object\"\u003e\u003c/script\u003e\n```\n\n## Change Log\n\nThis project adheres to [Semantic Versioning](http://semver.org/).  \nEvery release, along with the migration instructions, is documented on the Github [Releases](https://github.com/mbasso/script-wasm/releases) page.\n\n## Authors\n**Matteo Basso**\n- [github/mbasso](https://github.com/mbasso)\n- [@teo_basso](https://twitter.com/teo_basso)\n\n## Copyright and License\nCopyright (c) 2019, Matteo Basso.\n\nscript-wasm source code is licensed under the [MIT License](https://github.com/mbasso/script-wasm/blob/master/LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbasso%2Fscript-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbasso%2Fscript-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbasso%2Fscript-wasm/lists"}