Socket
Socket
Sign inDemoInstall

@automattic/load-script

Package Overview
Dependencies
4
Maintainers
21
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @automattic/load-script

Async Script Loader.


Version published
Maintainers
21
Install size
386 kB
Created

Readme

Source

Async Script Loader

This utility function allows us to use a standardized method of loading remote scripts and injecting them into the <head> of our document to bring external functionality into the app.

Usage

import { loadScript, loadjQueryDependentScript } from '@automattic/load-script';
loadScript( REMOTE_SCRIPT_URL, function( error ) {
	if ( error ) {
		debug( 'Script ' + error.src + ' failed to load.' );
		return;
	}
	debug( 'Script loaded!' );
} );

// if we need jQuery, this function will load it (if it's not loaded already)
loadjQueryDependentScript( REMOTE_SCRIPT_URL, function( error ) {
	if ( error ) {
		debug( 'Script ' + error.src + ' failed to load.' );
		return;
	}
	debug( 'Script and jQuery are loaded!' );
} );

Error handling

The callback should expect a single argument, which will be null on success or an object on failure. The object contains the src property, which will contain the src url of the script that failed to load.

Keywords

FAQs

Last updated on 03 Jun 2019

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc