
Product
Introducing Custom Tabs for Org Alerts
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.
@wordpress/asset-loader
Advanced tools
Utility to dynamically load WordPress scripts and styles with dependency resolution.
Utility to dynamically load WordPress scripts and styles with dependency resolution.
This package provides a function to dynamically inject WordPress assets (scripts and styles) into the DOM with:
wp_enqueue_script/wp_enqueue_style behaviorInstall the module:
npm install @wordpress/asset-loader --save
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
);
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: {} }
);
}
Loads WordPress assets with dependency resolution.
Record<string, Script> - Map of script handles to script dataRecord<'before' | 'after', Record<string, string | string[]>> - Inline scriptsRecord<string, Style> - Map of style handles to style dataRecord<'before' | 'after', Record<string, string | string[]>> - Inline stylesPromise<void> - Resolves when all assets are loaded and executed
type Script = {
src: string;
deps?: string[];
version?: string;
in_footer?: boolean;
};
type Style = {
src: string;
deps?: string[];
version?: string;
media?: string;
};
in_footer flagasync=false for order)See CONTRIBUTING.md.
GPL-2.0-or-later
FAQs
Utility to dynamically load WordPress scripts and styles with dependency resolution.
The npm package @wordpress/asset-loader receives a total of 1,194 weekly downloads. As such, @wordpress/asset-loader popularity was classified as popular.
We found that @wordpress/asset-loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 23 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.

Product
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.