You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 6, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 6, 2022. It is now read-only.
Implement block specific scripts similar to stylesheets #506
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)
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.
Activity
kienstra commentedon Jan 21, 2020
Hi @cameronjonesweb,
Thanks a lot for bringing this up, and for the details. We'll think about this 😄
kienstra commentedon 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.
Still, more testing is needed before writing off this idea. I think enqueuing JS could be really useful.
kienstra commentedon Jan 25, 2020
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:
block-lab/php/blocks/class-loader.php
Line 404 in 32e71bb
Of course, that's not as useful as Block Lab doing the enqueuing automatically 😄
Have a great rest of the weekend.