Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@beyonk/async-script-loader
Advanced tools
Allows asynchronous loading of scripts and styles in a Single Page Application (or anything else, in fact):
Having 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.
You 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.
Urls can be scripts or stylesheets.
You 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.
<script>
import loader from '@beyonk/async-script-loader'
const url = '//example.com/sdk/1.0.0/lib.js'
function test () {
return !!window.PROVIDER
}
function callback () {
window.PROVIDER.someFunction()
}
loader([
{ type: 'script', url }
], test, callback)
</script>
You can pass options for script tags.
<script>
loader([
{ type: 'script', url, options: { async: true, defer: true } } // these are the default options
], test, callback)
</script>
You can include any number of tags, including style tags.
When the last one has loaded, the callback will be called.
<script>
import loader from '@beyonk/async-script-loader'
loader([
{ type: 'script', url: '//example.com/sdk/1.0.0/lib.js' },
{ type: 'script', url: '//example.com/sdk/1.0.0/lib2.js' },
{ type: 'style', url: '//example.com/sdk/1.0.0/style.css' }
], () => {
return !!window.PROVIDER
}, () => {
window.PROVIDER.someFunction()
})
</script>
No more tears!
FAQs
Loads scripts cleanly and asynchronously in SPAs
The npm package @beyonk/async-script-loader receives a total of 959 weekly downloads. As such, @beyonk/async-script-loader popularity was classified as not popular.
We found that @beyonk/async-script-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.