Commit 9d03e8e
committed
Editor: Avoid enqueueing assets for blocks which do not render content.
This change prevents scripts, styles, and script modules from being enqueued for blocks that do not render any HTML content. This is common for hidden blocks or blocks like the Featured Image block when no image is present. This change reduces the amount of unused CSS and JavaScript on a page, improving performance.
A new filter, `enqueue_empty_block_content_assets`, is introduced to allow developers to override this behavior and enqueue assets for empty blocks if needed.
The implementation involves capturing the asset queues before and after a block is rendered. The newly enqueued assets are only merged if the block's rendered content is not empty. This is done recursively for nested blocks to ensure that assets for inner blocks are also not enqueued if a parent block is hidden.
Developed in WordPress#9213.
Props westonruter, aristath, peterwilsoncc, gziolo, krupajnanda, dd32, jorbin.
See #50328.
Fixes #63676.
git-svn-id: https://develop.svn.wordpress.org/trunk@60930 602fd350-edb4-49c9-b593-d223f7449a821 parent b3c3c8e commit 9d03e8e
5 files changed
Lines changed: 408 additions & 28 deletions
File tree
- src/wp-includes
- tests/phpunit/tests
- blocks
- script-modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
495 | 503 | | |
496 | 504 | | |
497 | 505 | | |
| |||
661 | 669 | | |
662 | 670 | | |
663 | 671 | | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
664 | 710 | | |
665 | 711 | | |
666 | 712 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | | - | |
29 | | - | |
| 28 | + | |
| 29 | + | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
126 | 125 | | |
127 | 126 | | |
128 | 127 | | |
| |||
213 | 212 | | |
214 | 213 | | |
215 | 214 | | |
216 | | - | |
217 | | - | |
218 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
219 | 219 | | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | 220 | | |
224 | 221 | | |
225 | 222 | | |
| |||
231 | 228 | | |
232 | 229 | | |
233 | 230 | | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
| 231 | + | |
238 | 232 | | |
239 | 233 | | |
240 | 234 | | |
| |||
245 | 239 | | |
246 | 240 | | |
247 | 241 | | |
| 242 | + | |
248 | 243 | | |
249 | | - | |
250 | 244 | | |
251 | 245 | | |
252 | 246 | | |
| |||
304 | 298 | | |
305 | 299 | | |
306 | 300 | | |
307 | | - | |
| 301 | + | |
308 | 302 | | |
309 | | - | |
| 303 | + | |
310 | 304 | | |
311 | 305 | | |
312 | 306 | | |
| |||
345 | 339 | | |
346 | 340 | | |
347 | 341 | | |
348 | | - | |
| 342 | + | |
349 | 343 | | |
350 | 344 | | |
351 | 345 | | |
| |||
359 | 353 | | |
360 | 354 | | |
361 | 355 | | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
369 | 360 | | |
370 | 361 | | |
371 | 362 | | |
| |||
457 | 448 | | |
458 | 449 | | |
459 | 450 | | |
460 | | - | |
| 451 | + | |
461 | 452 | | |
462 | 453 | | |
463 | 454 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
34 | 42 | | |
35 | 43 | | |
36 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
37 | 49 | | |
38 | 50 | | |
39 | 51 | | |
| |||
42 | 54 | | |
43 | 55 | | |
44 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
45 | 67 | | |
46 | 68 | | |
47 | 69 | | |
| |||
0 commit comments