[wp-trac] [WordPress Trac] #53507: Block style version: replace filemtime with version from Block API metadata

WordPress Trac noreply at wordpress.org
Tue Jun 29 18:04:41 UTC 2021


#53507: Block style version: replace filemtime with version from Block API metadata
------------------------------+-----------------------
 Reporter:  hellofromTonya    |       Owner:  desrosj
     Type:  defect (bug)      |      Status:  assigned
 Priority:  normal            |   Milestone:  5.8
Component:  Script Loader     |     Version:  5.5
 Severity:  normal            |  Resolution:
 Keywords:  has-patch commit  |     Focuses:
------------------------------+-----------------------
Description changed by desrosj:

Old description:

> In `register_block_style_handle` function, the version used for
> registering a style handle is the file's modification time (via
> `filemtime`).
>
> This should be removed in favor of using the block's version in its
> metadata.
>
> Why?
>
> A block is a package. In that package is everything the block needs
> including its script and styles. When the block changes, the version
> reflects the block's new version. Following that line of thinking, the
> version registered via the [https://developer.wordpress.org/block-editor
> /reference-guides/block-api/block-metadata/#wpdefinedasset Block API] is
> the block's version, meaning its the version for the script and styles.
>
> Setting the version is optional. When it's not set, then like other
> assets, it defaults to `false`.
>
> Why not `filemtime()`?
> Performance. This function hits the filesystem which takes time and
> memory. Using it in development is the norm and acceptable. But in
> production, it's less performant than using the supplied version when
> registering the block.

New description:

 In `register_block_style_handle` function, the version used for
 registering a style handle is the file's modification time (via
 `filemtime`).

 This should be removed in favor of using the block's version in its
 metadata.

 Why?

 A block is a package. In that package is everything the block needs
 including its script and styles. When the block changes, the version
 reflects the block's new version. Following that line of thinking, the
 version registered via the [https://developer.wordpress.org/block-editor
 /reference-guides/block-api/block-metadata/#wpdefinedasset Block API] is
 the block's version, meaning its the version for the script and styles.

 Setting the version is optional. When it's not set, then like other
 assets, it defaults to `false`.

 Why not `filemtime()`?
 Performance. This function hits the filesystem which takes time and
 memory. Using it in development is the norm and acceptable. But in
 production, it's less performant than using the supplied version when
 registering the block.

 This is a follow-up ticket to #53375.

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53507#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list