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

WordPress Block Script and Style Registration Only #12

Merged
merged 7 commits into from
Oct 17, 2023

Conversation

rleeson
Copy link
Contributor

@rleeson rleeson commented Oct 17, 2023

Description

As a developer, I want to support the ability for WordPress to only add Black CSS and JS for pages where the associated block is actually used.

The adds functions register_script_handle and register_style_handle which allow dynamic inclusion in Production mode. Due to limitations in Dev mode, things always run as scripts, this method does not work without further effort. Since this is primarily a performance optimization for Production, this is an acceptable trade-off for now.

Steps to Validate

  1. Update to this feature on a Kanopi Pack based WordPress project using Gutenberg blocks.
  2. Add a new Test block along with new entry points for its CSS and JS
  3. Use the register_script_handle and register_style_handle functions to add the entry points where other scripts and styles are registered
  4. Update the block.json to use the prefixed handles for the CSS and JS entries
  5. Add the block to a page
  6. Check in Dev mode and ensure styles and scripts work.
  7. Compile and switch to Production mode.
  8. Ensure the CSS and JS only load on pages where the block is used.

@rleeson rleeson merged commit 1380d93 into main Oct 17, 2023
@rleeson rleeson deleted the feature/register-only branch October 23, 2023 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants