Dynamic vs Static
WordPress provides two options for the creation of custom blocks: Dynamic, and Static.
For the purposes of ID, most if not all the custom blocks that we will build, whether as part of a plugin, in a theme, or core to our parent themes will be built using dynamic blocks. We will have few use cases for static blocks.
Dynamic Blocks
A dynamic block is a piece of content whose markup and exact content are not known when the page is saved. This block could contain content that is timely or dependent on changes in other parts of the site. The contents of a dynamic block are expected to change without the intervention of a content editor. As a result, the markup of a dynamic block is rendered on the server-side.
Advantages of Dynamic Blocks
- Allows for changes or updates without re-compile of the JS
- Keeps markup and logic in php so that we can create (more easily) more complicated layouts
- We can add in hooks above and below output, or as needed
- Layout is not stored in database, just the data
- Allows use of templates and partials, which can be overridden in custom themes
Disadvantages of Dynamic Blocks
- Splits the editor and presentation layers into 2 different languages (JS and PHP respectively)
How Dynamic Blocks Benefit ID
Content requested
Structure Of A Dynamic Block
Update once the final structure has been decided.
Static Block
A static block is a piece of content whose markup is known when the page is saved. The block saves its content and markup directly in the post content. The Paragraph block is a simple example of a static block.
Advantages of Static Blocks
Static blocks are inherently simpler because they are written in a single language, JavaScript. Their markup is known at the time the page is saved, so, as mentioned above, all of that HTML code can be saved directly to the database.
This approach is more performant. When a visitor views the page, the content comes from the database. There is no delay in displaying the block since no server-side rendering is required.
Disadvantages of Static Blocks
If a static block’s code structure has been modified, the posts using that block will throw an error. In order to prevent that from happening, additional code is needed to deprecate.