Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach css and js to patterns #61881

Open
Lovor01 opened this issue May 22, 2024 · 0 comments
Open

Attach css and js to patterns #61881

Lovor01 opened this issue May 22, 2024 · 0 comments
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.

Comments

@Lovor01
Copy link
Contributor

Lovor01 commented May 22, 2024

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.

register_pattern_script('url', 'pattern_slug');
register_pattern_style('url', 'pattern_slug');
@Lovor01 Lovor01 added the [Type] Enhancement A suggestion for improvement. label May 22, 2024
@jordesign jordesign added the [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced label May 24, 2024
@gziolo gziolo added the Needs Technical Feedback Needs testing from a developer perspective. label Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

3 participants