Opened 6 years ago
Last modified 4 years 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: |
Description
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:
- How to detect what scripts/stylesheets are required to display a particular page/post body
- How to return that information over the REST API
- 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)
#3
@
6 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.
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