• Resolved Jono Alderson

    (@jonoaldersonwp)


    Is there an easy way to conditionally check whether a request is returning service worker content?

    E.g., what would an equivalent of is_archive() or is_singular() look like for requests to example.com/?wp_service_worker=1 and similar (including example.com/?wp_error_template=offline, example.com/?wp_error_template=500, and others)?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    For the service worker, you could use this: false !== get_query_var( 'wp_service_worker', false ) or just (bool) get_query_var( 'wp_service_worker' ).

    For the offline page, use function_exists( 'is_offline' ) && is_offline().

    For the internal error page, use function_exists( 'is_500' ) && is_500().

    Thread Starter Jono Alderson

    (@jonoaldersonwp)

    Thanks! I have a few use-cases where I’m altering/adding HTTP headers, and don’t want to do this on service worker responses.

    It’d awesome if we could get a is_service_worker(), too, to keep this clean and consistent.

    Plugin Author Weston Ruter

    (@westonruter)

    Yeah, I suppose we need that now that we also have is_robots() and is_favicon().

    Plugin Author Weston Ruter

    (@westonruter)

    Follow-up on is_service_worker(): https://github.com/GoogleChromeLabs/pwa-wp/issues/301

    • This reply was modified 4 years, 5 months ago by Weston Ruter.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to best determine if a request returns service worker content?’ is closed to new replies.