Make WordPress Core

Opened 3 years ago

Last modified 15 months ago

#46379 new feature request

REST API posts/pages response to include scripts needed for display of post content

Reported by: mnelson4 Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: REST API Keywords:
Focuses: Cc:


Often post body is dependent on external scripts and stylesheets in order to be displayed correctly, but there is no way to discover what those scripts/stylesheets are.
This problem was encountered in Gutenberg on https://github.com/WordPress/gutenberg/pull/9734, and the fix was to filter the REST API response to include the list of scripts.

You can't know what the scripts are required ahead of time, especially if the API client code is being run from a different server. Shortcodes and Gutenberg blocks can dynamically add scripts and stylesheets.

So, I think the problem is three-fold:

  1. How to detect what scripts/stylesheets are required to display a particular page/post body
  2. How to return that information over the REST API
  3. How can API clients (like the backbone client) use that to display the post's body correctly (with the required javascript/stylesheets)

Change History (7)

#1 @desrosj
3 years ago

  • Milestone changed from Awaiting Review to Future Release

#2 @mnelson4
3 years ago

Oh, also some context on an application: I have a plugin that loads a ton of posts via the REST API and dumps their post bodies into the page. But posts with shortcodes often don't appear correctly because they enqueue javascript which is never returned over the REST API. See https://github.com/mnelson4/printmyblog/issues/9

#3 @mnelson4
3 years ago

I suspect I'll first need to create a feature plugin that attempts to fix this, but ideally a fix will eventually land in core. I've mostly created this in case anyone has great suggestions.

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.

3 years ago

This ticket was mentioned in Slack in #core-restapi by mnelson4. View the logs.

2 years ago

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.

18 months ago

#7 @TimothyBlynJacobs
15 months ago

  • Type changed from defect (bug) to feature request

Related #48654.

Note: See TracTickets for help on using tickets.