pushpad / pushpad-wordpress

Pushpad WordPress plugin: easily add push notifications to your WordPress website.
https://pushpad.xyz
4 stars 1 forks source link

Generate manifest using WP_Serve_File #2

Open marco-c opened 7 years ago

marco-c commented 7 years ago

The current mechanism you're using is bound to fail in many WordPress configurations. WP_Serve_File supports several ways to generate the manifest file (it will always use the best option according to the permissions the WordPress configuration has).

collimarco commented 7 years ago

The problem with your solution is that it will fail if other plugins need to serve a manifest. The same can be said for the service worker. This is because you cannot have multiple manifests or service workers for the same page.

The solution used for this plugin allows to merge the contents of that files in case they are already in use for other purposes. I don't see any way to achieve that with WP_Serve_File.

marco-c commented 7 years ago

If there's already a manifest.json file, you can read it and add your contents to the already existing content and then serve it via WP_Serve_File.

collimarco commented 7 years ago

Yes, I understand that. However what if multiple plugins generate the files (manifest, service worker) dynamically? There would be a conflict. Correct me if I am wrong, but I think that it's a better practice to write that files on disk: if everyone does so, there won't be any conflict. Moreover the user can solve any issue manually.

marco-c commented 7 years ago

The problem is that you can't know what other plugins are doing, so even if you write the file on disk, you don't know if you're compatible with other plugins. Notice that WP_Serve_File will write a file on disk if possible, if it isn't possible it will serve it dynamically: https://github.com/marco-c/WP_Serve_File/blob/master/WP_Serve_File.php#L46.

In theory the best solution would be to have a WordPress API for this, but it isn't available for now.

collimarco commented 3 weeks ago

It's 2024 - many years have passed - and WordPress still doesn't have an official way for plugins to add some code to the service worker.

This is another attempt of standardization https://github.com/GoogleChromeLabs/pwa-wp, but it hasn't been merged with Wordpress core yet...