Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
simple-load-script
Advanced tools
Very simple promise based script loader and JSONP
import simpleLoadScript from 'simple-load-script';
try {
const scriptRef = await simpleLoadScript('//code.jquery.com/jquery-2.2.3.js');
console.log(scriptRef); // HTMLScriptElement
} catch (err) {
console.log(err);
}
import simpleLoadScript from 'simple-load-script';
simpleLoadScript('//code.jquery.com/jquery-2.2.3.js')
.then(function (scriptRef) {
console.log(scriptRef);
})
.catch(function (err) {
console.log(err);
});
import simpleLoadScript from 'simple-load-script';
try {
const scriptRef = await simpleLoadScript({
url: '//code.jquery.com/jquery-2.2.3.js',
inBody: true,
attrs: { id: 'one', charset: 'UTF-8' },
});
console.log(scriptRef); // HTMLScriptElement inBody with attrs present
} catch (err) {
console.log(err);
}
Runs global callback (window.gmapiready)
import simpleLoadScript from 'simple-load-script';
try {
const scriptRef = await simpleLoadScript('//maps.googleapis.com/maps/api/js?&callback=gmapiready');
console.log(scriptRef); // HTMLScriptElement
} catch (err) {
console.log(err);
}
Runs global callback (window.elo)
var simpleLoadScript = require('simple-load-script');
try {
const scriptRef = await simpleLoadScript({
url: '//api.ipinfodb.com/v3/ip-city/?format=json&callback=elo',
removeScript: true,
});
console.log(scriptRef); // undefined
} catch (err) {
console.log(err);
}
import simpleLoadScript from 'simple-load-script';
try {
const scriptRefs = await simpleLoadScript([
'//maps.googleapis.com/maps/api/js?&callback=gmapiready',
{
url: '//api.ipinfodb.com/v3/ip-city/?format=json&callback=elo',
removeScript: true,
},
'//code.jquery.com/jquery-2.2.3.js',
]);
console.log(scriptRefs); // HTMLScriptElement[]
} catch (err) {
console.log(err);
}
Config | string | (Config | string)[]
interface Config {
url: string;
attrs?: Record<string, string>;
inBody?: boolean;
insertInto?: string | null;
removeScript?: boolean;
}
const defaultConfig = {
url: '',
attrs: {},
inBody: false,
insertInto: null,
removeScript: false,
};
url
- file to append to bodyattrs
- with attributes to append to script tag (charset
, type
, id
, …)inBody
- append to document.body
instead of document.head
insertInto
- CSS selector (an ID, class name, element name, etc.) to insert the script into. Overrides inBody
value.removeScript
- remove script tag after load; it's always removed on an errorCheck files or package.json
2.0.0
jsonp
removed form ConfigcallBackName
removed form ConfigremoveScript
changes - script is not removed by default on an errorcallBack
removed form Config - just run code after simpleLoadScript run (eg. console.log
in examples)FAQs
Very simple promise based script and JSONP
The npm package simple-load-script receives a total of 4,487 weekly downloads. As such, simple-load-script popularity was classified as popular.
We found that simple-load-script demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.