Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@beyonk/async-script-loader

Package Overview
Dependencies
Maintainers
6
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@beyonk/async-script-loader - npm Package Compare versions

Comparing version 2.2.2 to 2.3.0

16

index.js

@@ -15,7 +15,9 @@ function load (urls, test, callback) {

for (const { type, url, options = { async: true, defer: true }} of urls) {
for (const { type, url, content, options = { async: true, defer: true }} of urls) {
const isScript = type === 'script'
const tag = document.createElement(isScript ? 'script': 'link')
const attribute = isScript ? 'src' : 'href'
const hasUrl = Boolean(url).valueOf()
if (isScript) {
tag.src = url
tag.async = options.async

@@ -25,4 +27,12 @@ tag.defer = options.defer

tag.rel = 'stylesheet'
tag.href = url
}
if (hasUrl) {
tag[attribute] = url
} else {
tag.appendChild(
document.createTextNode(content)
)
}
tag.onload = maybeCallback

@@ -29,0 +39,0 @@ document.body.appendChild(tag)

2

package.json
{
"name": "@beyonk/async-script-loader",
"version": "2.2.2",
"version": "2.3.0",
"description": "Loads scripts cleanly and asynchronously in SPAs",

@@ -5,0 +5,0 @@ "keywords": [

@@ -87,1 +87,20 @@ <a href="https://beyonk.com">

No more tears!
#### Inline scripts / Inline css
You 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.
```js
<script>
import loader from '@beyonk/async-script-loader'
loader([
{ type: 'script', content: 'console.log("foo");' },
{ type: 'style', content: '* { color: red; }' }
],
() => false, // always load
() => () // no-op
)
</script>
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc