Make WordPress Core

Opened 5 months ago

Last modified 5 weeks ago

#62261 new enhancement

Theme JSON: cached resolved URIs

Reported by: ramonopoly's profile ramonopoly Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Themes Keywords: has-patch has-unit-tests gutenberg-merge
Focuses: Cc:

Description

A ticket to track the syncing of Gutenberg PR: https://github.com/WordPress/gutenberg/pull/66155

What

Implement "pretty basic caching" for resolved theme URIs in WP_Theme_JSON_Resolver::get_resolved_theme_uris.

The intention to improve performance, even if slightly.

WP_Theme_JSON_Resolver::get_resolved_theme_uris, and WP_Theme_JSON_Resolver::resolve_theme_file_uris which calls it, is fired multiple times in a single session to:

  1. Generate styles
  2. Deliver resolved URIs in a global styles controller response.

Results will become more pronounced as other relative paths are introduced, e.g., fonts, and more blocks support background images.

Cached data is not be stored persistently across page loads.

Change History (3)

This ticket was mentioned in PR #7596 on WordPress/wordpress-develop by @ramonopoly.


5 months ago
#1

Syncing https://github.com/WordPress/gutenberg/pull/66155

Trac ticket: https://core.trac.wordpress.org/ticket/62261

## What?

Implement "pretty basic caching" for resolved theme URIs in WP_Theme_JSON_Resolver::get_resolved_theme_uris.

## Why?

The intention to improve performance, even if slightly.

WP_Theme_JSON_Resolver::get_resolved_theme_uris, and WP_Theme_JSON_Resolver::resolve_theme_file_uris which calls it, is fired multiple times in a single session to:

  1. Generate styles
  2. Deliver resolved URIs in a global styles controller response.

Here are some preliminary results (higher response time is worse):

Uncached This PR (cached)

| https://github.com/user-attachments/assets/b99545bc-5941-4beb-9643-bd21b7752808 | https://github.com/user-attachments/assets/d956ed79-0a6f-4ee8-ad1d-89b0c98b8e8f |

Results will become more pronounced as other relative paths are introduced, e.g., fonts, and more blocks support background images.

Cached data is not be stored persistently across page loads.

## How?

Simple object caching.

## Testing Instructions

Run npm run test:unit:php:base -- --filter WP_Theme_JSON_Resolver_Gutenberg_Test

Create a theme.json with background image paths defined for several blocks.

Ensure these appear as expected in the editor and frontend.

In the theme.json file, replace one or several paths with new asset paths. Check that the styles have been updated and the editor/frontend looks good.

Here is some test JSON based on current assets in TT5:

{
        "$schema": "../../schemas/json/theme.json",
        "version": 3,
        "settings": {
                "appearanceTools": true
        },
        "styles": {
                "background": {
                        "backgroundImage": {
                                "url": "file:./assets/images/category-anthuriums.webp"
                        }
                },
                "blocks": {
                        "core/group": {
                                "background": {
                                        "backgroundImage": {
                                                "url": "file:./assets/images/category-cactus.webp"
                                        }
                                }
                        },
                        "core/post-content": {
                                "background": {
                                        "backgroundImage": {
                                                "url": "file:./assets/images/hero-podcast.webp"
                                        }
                                }
                        },
                        "core/quote": {
                                "background": {
                                        "backgroundImage": {
                                                "url": "file:./assets/images/category-sunflowers.webp"
                                        }
                                }
                        },
                        "core/pullquote": {
                                "background": {
                                        "backgroundImage": {
                                                "url": "file:./assets/images/dallas-creek-square.webp"
                                        }
                                }
                        }
                }
        }
}

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


5 weeks ago

#3 @audrasjb
5 weeks ago

  • Milestone changed from 6.8 to Future Release

Given the Gutenberg PR is not on the 6.8 project board, let's move this ticket to Future Release.

Note: See TracTickets for help on using tickets.