Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Implement block specific scripts similar to stylesheets #506

Open
cameronjonesweb opened this issue Jan 21, 2020 · 3 comments
Open

Implement block specific scripts similar to stylesheets #506

cameronjonesweb opened this issue Jan 21, 2020 · 3 comments

Comments

@cameronjonesweb
Copy link

Feature description

As defined in #249, styles can be automatically included when the block is active on a page. I think it would be nice if block scripts could be included on the front end in a similar manner.

Screenshot (optional)

image

Use case

There are plenty of types of block that could utilise front end only scripts. An accordion panel for example, or tabbed content.

Additional information

Just think this could be a good feature, considering styles are already loaded this way.

@kienstra
Copy link
Collaborator

Hi @cameronjonesweb,
Thanks a lot for bringing this up, and for the details. We'll think about this 😄

@kienstra
Copy link
Collaborator

kienstra commented Jan 25, 2020

This could be a really useful idea, enqueuing JS for blocks.

My only concern might be performance. I should do another PHP profiling test to see the cost of this.

So far, it looks like the performance cost of BL enqueuing block stylesheets is high, compared to the overall performance cost of BL.

For example, the CPU time of Block_Lab\Util::locate_template() in this profile is 7.6 ms and the clock (real) time is 19.3 ms, compared to an overall performance cost of BL of about 87 ms.

locate_template

Still, more testing is needed before writing off this idea. I think enqueuing JS could be really useful.

@kienstra
Copy link
Collaborator

Hi @cameronjonesweb,
Thanks a lot for suggesting this.

In the meantime, in case you didn't notice it, there's an action where you could enqueue scripts for a block:

do_action( 'block_lab_render_template', $block, $attributes );

Of course, that's not as useful as Block Lab doing the enqueuing automatically 😄

Have a great rest of the weekend.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants