Attach css and js to patterns #61881
Labels
[Feature] Patterns
A collection of blocks that can be synced (previously reusable blocks) or unsynced
Needs Technical Feedback
Needs testing from a developer perspective.
[Type] Enhancement
A suggestion for improvement.
Problem
In the early days of Gutenberg, I used to build block for everything to create pages. That was such, because I needed that user can insert complex unit as a whole. Nowadays, it is much faster working with patterns, creating a group of elements and creating pattern out of that. However, there is still problem with optimising css/js if those patterns require special css or js and most of them do.
I can either enqueue all needed css/js on every post/page or eventually guess on which pages user will need those patterns and enqueue css/js only there. It would be much more useful that system remembers a pattern being used on a page and enqueues given css/js only there where pattern is used, much like with blocks.
Solution
Developing a system which would somehow store occurence of pattern on post/page, either as another comment in content (similar to block) or post metadata. Also, enhancing pattern definition so css/js could be attached to it. This part would be very easy, since pattern has a unique slug, css and js could be enqueued with dedicated functions receiving css/js url and pattern slug.
e.g.
The text was updated successfully, but these errors were encountered: