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

Frontend loading of block assets #11231

Closed
enejb opened this issue Oct 30, 2018 · 1 comment
Closed

Frontend loading of block assets #11231

enejb opened this issue Oct 30, 2018 · 1 comment
Labels
[Type] Enhancement A suggestion for improvement.

Comments

@enejb
Copy link
Contributor

enejb commented Oct 30, 2018

Is your feature request related to a problem? Please describe.
Currently when a block is included to be displayed on the front end of the site (not wp-admin). The preferred way to include the assets (js and css) for that block seems to be via the enqueue_block_assets action or by registering the scripts and style attributes in as attributes of the block in the register_block_type() function.

The problem is if a particular block requires a lot of JS code for example currently the JS could gets included on every page load if that block is present or not.

Describe the solution you'd like
It would be great if we could pass an attribute when registering the block that we only want to load the script and styles when the block is being displayed.

Currently I am implementing something that use the render_callback attribute and adds the loading of the assets in there. See https://github.com/Automattic/jetpack/pull/10405/files

But I think a solution to this issue that is supported in Gutenberg would be best.
I would be more then happy to code something up but wanted to ask first if this is something we would consider.

cc: @aduth

@earnjam earnjam added the [Type] Enhancement A suggestion for improvement. label Oct 30, 2018
@aduth
Copy link
Member

aduth commented Oct 30, 2018

I think this is related to #2756 and #5445, likely a duplicate in the latter case. Let's consolidate discussion there.

I anticipate a solution could leverage the script field of a registered block type added in #4039, so using it now could allow it to be enhanced automatically (i.e. future compatible).

@aduth aduth closed this as completed Oct 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants