Open westonruter opened 5 years ago
This is certainly a great use case for wp.hooks
and will be a familiar approach to WordPress developers. @westonruter - would introducing a single filter here be sufficient to resolve this issue?
I'm sure there are plenty of other cases where filtering in JS would give the flexible extensibility that would be required.
New the codebase here, can you clarify what other areas you think will benefit from additional JS extensibility?
The use case I see having immediate benefit is using the filter for plugins to be able to dynamically modify the content of the offline page, such as injecting a list of links that are available offline. So I'd start exploring that in #211.
Started playing around with this in #234.
In order to facilitate themes and plugins to perform manipulations in the service worker,
There is code in
service-worker-navigation-routing.js
andservice-worker-offline-commenting.js
that could benefit from hook extensibility (among other scripts).For example, instead of there being one single navigation caching strategy registered for every URL which is then used in the the service worker:
https://github.com/xwp/pwa-wp/blob/a66f599fc27c7c0e2d85e649d8b4831a009ce1a4/wp-includes/js/service-worker-navigation-routing.js#L138
The
CACHING_STRATEGY
andCACHING_STRATEGY_ARGS
could be filtered, with theevent
passed to the filter to decide dynamically what the caching strategy should be.I'm sure there are plenty of other cases where filtering in JS would give the flexible extensibility that would be required.