{"id":28385784,"url":"https://github.com/beyonk-group/async-script-loader","last_synced_at":"2025-06-26T12:31:19.282Z","repository":{"id":42079130,"uuid":"188312767","full_name":"beyonk-group/async-script-loader","owner":"beyonk-group","description":"Asynchronous script loading for SPAs","archived":false,"fork":false,"pushed_at":"2022-11-12T11:55:04.000Z","size":34,"stargazers_count":17,"open_issues_count":7,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-30T13:47:54.092Z","etag":null,"topics":["async","cdn","defer","event","javascript","onload","script","sdk","spa","unpkg"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beyonk-group.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-23T22:02:57.000Z","updated_at":"2023-06-16T01:56:41.000Z","dependencies_parsed_at":"2022-08-12T04:20:16.830Z","dependency_job_id":null,"html_url":"https://github.com/beyonk-group/async-script-loader","commit_stats":null,"previous_names":["beyonk-group/async-script-loader"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/beyonk-group/async-script-loader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyonk-group%2Fasync-script-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyonk-group%2Fasync-script-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyonk-group%2Fasync-script-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyonk-group%2Fasync-script-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beyonk-group","download_url":"https://codeload.github.com/beyonk-group/async-script-loader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyonk-group%2Fasync-script-loader/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262067856,"owners_count":23253684,"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":["async","cdn","defer","event","javascript","onload","script","sdk","spa","unpkg"],"created_at":"2025-05-30T11:44:05.556Z","updated_at":"2025-06-26T12:31:19.269Z","avatar_url":"https://github.com/beyonk-group.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca href=\"https://beyonk.com\"\u003e\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003cimg src=\"https://user-images.githubusercontent.com/218949/144224348-1b3a20d5-d68e-4a7a-b6ac-6946f19f4a86.png\" width=\"198\" /\u003e\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n\u003c/a\u003e\n\n## Async Script Loader\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com) \n\nAllows asynchronous loading of scripts and styles in a Single Page Application (or anything else, in fact):\n\n* Using a test to ensure that the code is only loaded once\n* Running a callback once the script is loaded\n* Running a callback if the script is already loaded\n* Not blocking the main thread\n\n### Reasoning\n\nHaving integrated a multitude of third-party SDKs from large, well known providers, I've come to the conclusion that not having a standard interface turns the whole thing into a minefield of callbacks, timers, random library-specific loader modules, and global objects on the window, resulting in XSS risks and all sort of other undesirable behaviour. This module aims to provide a standard way of loading third-party dependencies.\n\n### Usage\n\nYou pass a list of urls to the loader, along with a method for checking that your page is ready, and a callback to call when it is.\n\nUrls can be scripts or stylesheets.\n\n### Script Tags\n\nYou can use the module like so, for a library loaded from example.com, which, when loaded, adds an attribute called PROVIDER to the global window object.\n\n```js\n\u003cscript\u003e\n  import loader from '@beyonk/async-script-loader'\n\n  const url = '//example.com/sdk/1.0.0/lib.js'\n\n  function test () {\n    return !!window.PROVIDER\n  }\n\n  function callback () {\n    window.PROVIDER.someFunction()\n  }\n\n  loader([\n    { type: 'script', url }\n  ], test, callback)\n\u003c/script\u003e\n```\n\nYou can pass options for script tags.\n\n```js\n\u003cscript\u003e\n  loader([\n    { type: 'script', url, options: { async: true, defer: true } } // these are the default options\n  ], test, callback)\n\u003c/script\u003e\n```\n\n#### Style Tags\n\nYou can include any number of tags, including style tags.\n\nWhen the last one has loaded, the callback will be called.\n\n```js\n\u003cscript\u003e\n  import loader from '@beyonk/async-script-loader'\n\n  loader([\n    { type: 'script', url: '//example.com/sdk/1.0.0/lib.js' },\n    { type: 'script', url: '//example.com/sdk/1.0.0/lib2.js' },\n    { type: 'style', url: '//example.com/sdk/1.0.0/style.css' }\n  ], () =\u003e {\n    return !!window.PROVIDER\n  }, () =\u003e {\n    window.PROVIDER.someFunction()\n  })\n\u003c/script\u003e\n```\n\nNo more tears!\n\n#### Inline scripts / Inline css\n\nYou can use inline content for either type of tag by passing the configuration attribute `content` *instead* of `url`. This will write the content passed into the tag's body rather than setting it as an `href` or `src` attribute `url` will always take prescidence, so leave it out for `content` to work.\n\n\n```js\n\u003cscript\u003e\n  import loader from '@beyonk/async-script-loader'\n\n  loader([\n    { type: 'script', content: 'console.log(\"foo\");' },\n    { type: 'style', content: '* { color: red; }' }\n  ],\n  () =\u003e false, // always load\n  () =\u003e () // no-op\n)\n\u003c/script\u003e\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeyonk-group%2Fasync-script-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeyonk-group%2Fasync-script-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeyonk-group%2Fasync-script-loader/lists"}