npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wordpress/asset-loader

v1.17.0

Published

Utility to dynamically load WordPress scripts and styles with dependency resolution.

Readme

Asset Loader

Utility to dynamically load WordPress scripts and styles with dependency resolution.

Overview

This package provides a function to dynamically inject WordPress assets (scripts and styles) into the DOM with:

  • Dependency resolution - Respects WordPress dependency graphs via topological sort
  • Parallel loading - External scripts load in parallel for performance
  • Sequential execution - Inline scripts execute in the correct order
  • Inline scripts/styles - Supports before/after inline content per handle
  • WordPress compatibility - Mimics wp_enqueue_script/wp_enqueue_style behavior

Installation

Install the module:

npm install @wordpress/asset-loader --save

Usage

Basic Usage

import loadAssets from '@wordpress/asset-loader';

const assets = {
	scripts: {
		'wp-blocks': {
			src: 'https://example.com/wp-includes/js/dist/blocks.min.js',
			deps: [ 'wp-element', 'wp-data' ],
			version: '1.0.0',
			in_footer: true,
		},
	},
	styles: {
		'wp-block-library': {
			src: 'https://example.com/wp-includes/css/dist/block-library/style.min.css',
			deps: [],
			version: '1.0.0',
			media: 'all',
		},
	},
	inline_scripts: {
		before: {},
		after: {
			'wp-blocks': 'wp.blocks.registerBlockType(...)',
		},
	},
	inline_styles: {
		before: {},
		after: {},
	},
};

await loadAssets(
	assets.scripts,
	assets.inline_scripts,
	assets.styles,
	assets.inline_styles
);

With @wordpress/core-data

import { resolveSelect } from '@wordpress/data';
import { store as coreDataStore } from '@wordpress/core-data';
import { unlock } from './lock-unlock';
import loadAssets from '@wordpress/asset-loader';

async function loadEditorAssets() {
	// Get assets from the REST API endpoint
	const assets = await unlock(
		resolveSelect( coreDataStore )
	).getEditorAssets();

	// Load them into the DOM
	await loadAssets(
		assets.scripts || {},
		assets.inline_scripts || { before: {}, after: {} },
		assets.styles || {},
		assets.inline_styles || { before: {}, after: {} }
	);
}

API

loadAssets(scriptsData, inlineScripts, stylesData, inlineStyles)

Loads WordPress assets with dependency resolution.

Parameters

  • scriptsData Record<string, Script> - Map of script handles to script data
  • inlineScripts Record<'before' | 'after', Record<string, string | string[]>> - Inline scripts
  • stylesData Record<string, Style> - Map of style handles to style data
  • inlineStyles Record<'before' | 'after', Record<string, string | string[]>> - Inline styles

Returns

Promise<void> - Resolves when all assets are loaded and executed

Types

type Script = {
	src: string;
	deps?: string[];
	version?: string;
	in_footer?: boolean;
};

type Style = {
	src: string;
	deps?: string[];
	version?: string;
	media?: string;
};

How It Works

  1. Topological Sort - Orders assets based on dependencies using depth-first search
  2. Stylesheet Loading - Loads CSS files in dependency order with inline styles
  3. Script Loading - Separates head/body scripts based on in_footer flag
  4. Parallel Execution - External scripts load in parallel (with async=false for order)
  5. Inline Scripts - Execute after their corresponding external scripts load

Contributing

See CONTRIBUTING.md.

License

GPL-2.0-or-later