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

Implement block specific scripts similar to stylesheets #506

Open

Description

@cameronjonesweb

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.

Activity

  1. kienstra commented on Jan 21, 2020

    @kienstra
    Collaborator

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

  2. kienstra commented on Jan 25, 2020

    @kienstra
    Collaborator

    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.

  3. kienstra commented on Jan 25, 2020

    @kienstra
    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions