Performance: Media library management
This affects page load speed and interaction responsiveness when loading and managing media files in the WordPress admin and frontend.
Use pagination or infinite scroll with lazy loading thumbnails sized appropriately for display.
Query all media files without pagination or lazy loading, loading full-size images for thumbnails.
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Loading all media at once with full-size images | High (100+ nodes) | Multiple reflows | High paint cost due to large images | [X] Bad |
| Paginated media loading with thumbnails | Moderate (20-30 nodes per page) | Single reflow per page | Low paint cost with small images | [OK] Good |
| Embedding full-size images in posts | Low DOM nodes | Minimal reflows | High paint cost due to large images | [X] Bad |
| Using responsive images with srcset | Low DOM nodes | Minimal reflows | Low paint cost with optimized images | [OK] Good |
wp.media() in JavaScript to open the media uploader?wp_enqueue_media() loads all necessary scripts and styles for the media uploader.const frame = wp.media({ title: 'Select Image', multiple: false });
frame.open();jQuery(document).ready(function($) {
const frame = wp.media({ title: 'Choose File' });
frame.open();
});wp_enqueue_media() to load scripts; without it, wp.media is undefined or non-functional.multiple: true. const frame = wp.media({ title: 'Select Images', multiple: 'multiple' }); uses a string which is invalid. const frame = wp.media({ title: 'Select Images', multiple: false }); disables multiple selection. const frame = wp.media({ title: 'Select Images', multiple: 1 }); uses a number which is invalid.Pass the test and this pattern moves unknown