Skip to content

On-demand icon definitions #8

Open

Description

@suasgn

Currently Blockstudio 7 bundle a massive SVG icon definitions (https://github.com/inline0/blockstudio/tree/main/includes/icons).

It will be better if the definitions are served on-demand so the Blockstudio source code/built file are more lean.

We have built a similar workaround for the on-demand SVG icon library with Omni Icon plugin (https://github.com/nabasa-dev/omni-icon/), you may want to check our implementation, or maybe collaborate so we can make a bridge to connect them easily.

Activity

  1. suasgn commented on Mar 6, 2026

    @suasgn
    Author

    This is example of how our picowind theme integrate the picowind plugin: https://github.com/livecanvas-team/picowind/blob/main/src/Supports/OmniIcon.php

    <?php
    
    /**
     * Get an icon using Omni Icon plugin if available.
     *
     * @param string $iconName Icon name in format "prefix:icon-name" (e.g., "mdi:home", "local:my-logo", "omni:windpress")
     * @param array $attributes Optional HTML attributes to add to the SVG element
     * @return null|string the SVG HTML if exists, or null if couldn't found or plugin not active
     */
    function get_icon(string $iconName, array $attributes = [])
    {
        // Validate icon name format
        if (! str_contains($iconName, ':')) {
            return null;
        }
    
        try {
            $iconService = \OmniIcon\Plugin::get_instance()->container()->get(\OmniIcon\Services\IconService::class);
    
            // Convert boolean and numeric attributes to string representation
            foreach ($attributes as $key => $value) {
                if (is_bool($value)) {
                    $attributes[$key] = $value ? 'true' : 'false';
                } elseif (is_int($value) || is_float($value)) {
                    $attributes[$key] = (string) $value;
                }
            }
    
            // Use Omni Icon plugin's IconService to render the icon as HTML string
            return $iconService->get_icon($iconName, $attributes);
        } catch (\Exception $e) {
            // Log errors in debug mode
            if (defined('WP_DEBUG') && WP_DEBUG) {
                error_log("OmniIcon error: {$e->getMessage()}");
            }
            return null;
        }
    }
  2. Contributolo commented on Oct 24, 2026

    @Contributolo
    Collaborator

    Some numbers for this, measured on the 7.7.8 release ZIP (13.4 MB): includes/icons/ holds 44 sets with 34,946 icons, 5.8 MB of the ZIP and 23 MB unpacked on every site. The largest are simple-icons (5.0 MB raw, 2.0 MB zipped), material-design-icons (5 variants, 4.6 MB raw) and tabler (3.5 MB raw).

    #185 takes care of the runtime side: whole sets are no longer stored as transients (up to 5 MB per row in wp_options), and the editor fetches a set only when the picker is used. It does not make the ZIP smaller.

    Compressing the files on disk (gzip per set) would save disk space but almost nothing in the ZIP (under 2 %, the SVG paths do not compress further). Only shipping less data helps. A shape that would keep everything that works today:

    • A small core stays in the ZIP, for example fontawesome-free, heroicons, feather, bootstrap and octicons (0.9 MB zipped). The ZIP would go from 13.4 to about 8.5 MB.
    • The other sets are built by generate-icons.ts as separate files, attached to the release like blockstudio.zip, and installed from the admin on request into wp-content/blockstudio/icons/ (outside the plugin folder, so updates keep them), with checksums in a small manifest in the ZIP.
    • rest.php and bs_render_icon() share one lookup (core, then the installed sets), with a filter so other icon sources can plug in. A missing set keeps rendering nothing as today and gets a notice in the admin and the picker.
    • No network request at render time or on the frontend, the stored value {set, subSet, icon} stays the same.

    Sites that use a set outside the core would need to install it once after updating, so the update needs a notice. If this direction works for you (or you prefer a different core, or a separate icons plugin or Composer package instead of release assets), I am happy to send a PR.

  3. added
    enhancement
    on Nov 6, 2026
  4. Contributolo commented on Nov 11, 2026

    @Contributolo
    Collaborator

    A revision of my proposal above. The small core is a compromise that still breaks sites using a set outside of it, so I would drop it. The line would not be "core or not" but "existing or new install":

    • New installs: no icon set in the ZIP at all. A set is fetched the first time it is picked in the editor and stored in wp-content/blockstudio/icons/. The ZIP goes from 13.4 MB to about 7.6 MB.
    • Existing installs: keep all 44 sets, only in a different place. Rendering stays local, the stored value {set, subSet, icon} stays the same, nobody has to click anything.

    Doing this without a gap takes two releases, because WordPress removes the old plugin folder before the new code runs for the first time:

    1. Release A still ships includes/icons/ and copies it once to wp-content/blockstudio/icons/ on its first run (a local copy, no network). From then on rest.php and bs_render_icon() read from there, through one shared lookup with a filter for other icon sources.
    2. Release B drops the folder from the ZIP. Sites that came through A notice nothing.

    What remains:

    • Skipping A: a site that updates from an older version straight to B has no local copy. B would fetch the sets once in the background (5.8 MB, release assets with checksums). Until that has finished icons are missing, and a server without outbound access to GitHub needs an admin notice. This is the only case where anything changes for anyone.
    • No disk savings on existing installs: the 22 MB stay, just outside the plugin folder. Unused sets could be removable from the admin.
    • No network request at render time or on the frontend, as before.

    Keeping only the sets a site actually uses is not reliable: bs_render_icon() can be called from any template with any set, so usage cannot be detected safely.

    If this direction works for you I will send the PR for release A first, since it changes nothing visible and can ship on its own.

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions