GoogleChromeLabs / pwa-wp

WordPress feature plugin to bring Progressive Web Apps (PWA) to Core
https://wordpress.org/plugins/pwa/
GNU General Public License v2.0
613 stars 98 forks source link

Introduce availability of wp.hooks in service worker #142

Open westonruter opened 5 years ago

westonruter commented 5 years ago

In order to facilitate themes and plugins to perform manipulations in the service worker,

There is code in service-worker-navigation-routing.js and service-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 and CACHING_STRATEGY_ARGS could be filtered, with the event 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.

adamsilverstein commented 4 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?

westonruter commented 4 years ago

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.

westonruter commented 4 years ago

Started playing around with this in #234.