jetpack icon indicating copy to clipboard operation
jetpack copied to clipboard

VideoPress block always renders scripts, doesn't use wp_enqueue_*

Open danieliser opened this issue 1 year ago • 3 comments

Impacted plugin

VideoPress

Quick summary

As it states, if you insert multiple VideoPress blocks you will end up trying to load the iframe JS API script every time.

It should be enqueued.

Steps to reproduce

Insert VideoPress block twice.

A clear and concise description of what you expected to happen.

Should enqueue the script properly and only load it once.

What actually happened

It loads under every iframe

Impact

Some (< 50%)

Available workarounds?

No but the platform is still usable

Platform (Simple and/or Atomic)

No response

Logs or notes

No response

danieliser avatar Feb 24 '24 10:02 danieliser

Somewhat related: #32235

jeherve avatar Feb 26 '24 10:02 jeherve

@jeherve - it does appear so, but this one is a bit more explicit about the issue and solution.

danieliser avatar Mar 01 '24 07:03 danieliser

This issue has been marked as stale. This happened because:

  • It has been inactive for the past 6 months.
  • It hasn’t been labeled `[Pri] BLOCKER`, `[Pri] High`, `[Type] Feature Request`, `[Type] Enhancement`, `[Type] Janitorial`, `Good For Community`, `[Type] Good First Bug`, etc.

No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.

github-actions[bot] avatar Aug 29 '24 00:08 github-actions[bot]

Still an issue last I checked.

danieliser avatar Sep 08 '24 06:09 danieliser

The optimization of VideoPress blocks is challenging due to the nature of their implementation.

Videos are rendered via a dedicated URL at video.wordpress.com, and each block is iframed, loading scripts such as videopress-routes and videopress-iframe. Since we have no control over the content within the iframe, we cannot prevent the duplication of script loads. As a result, having multiple VideoPress blocks (e.g., five) in the editor leads to loading the same scripts multiple times.

Example with 3 VP blocks within the editor:

Image

Because of the nature of the implementation, I'm not sure we can optimize this, so I'm closing the ticket.

cc @phcp @ouikhuan @Imran92

bogiii avatar Mar 18 '25 11:03 bogiii

@bogiii - I'm not sure that is the same thing. This ticket has nothing to do with what the iframes loaded.

My report was in regards to the file loaded from your own site that allows running the VideoPress API calls. These scripts are loaded outside of the iframe and let you interact with it.

You can see the shortcode does appear to enqueue them: https://github.com/Automattic/jetpack/blame/d3d9f829f1011955752ac241563af331a0a8a33b/projects/packages/videopress/src/class-block-editor-content.php#L139

I didn't see how the block was loading it, but from my original testing the blocks do not use the enqueued script, but inject it directly.

They should be adhering to enqueued script patterns for deduplciation as well.

danieliser avatar Mar 21 '25 22:03 danieliser

Reopening this issue to address the issue mentioned above. If I understood correctly, this is the line where the script is being loaded repeatedly: https://github.com/Automattic/jetpack/blob/trunk/projects/plugins/jetpack/modules/videopress/class.videopress-player.php#L713

phcp avatar Mar 31 '25 13:03 phcp