
Product
Introducing Reports: An Extensible Reporting Framework for Socket Data
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.
@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 806 weekly downloads. As such, @wordpress/asset-loader popularity was classified as not 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
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.