Performance: Block development basics
MEDIUM IMPACT
This affects the page load speed and interaction responsiveness by how blocks are registered and rendered in WordPress editor and frontend.
import { registerBlockType } from '@wordpress/blocks'; import Edit from './edit'; import save from './save'; import './style.css'; registerBlockType('myplugin/block', { edit: Edit, save, });
wp.blocks.registerBlockType('myplugin/block', { edit: () => { return wp.element.createElement('div', null, 'Hello World'); }, save: () => { return wp.element.createElement('div', null, 'Hello World'); }, // Inline styles and scripts added directly in edit and save });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline scripts and styles in block | Moderate DOM nodes | Multiple reflows due to style recalculations | High paint cost from unoptimized styles | [X] Bad |
| Separate JS and CSS files for block | Same DOM nodes | Single reflow after style load | Lower paint cost due to cached styles | [OK] Good |