Support » Plugin: Super Progressive Web Apps » Service worker caching /wp-json/ URLs

  • Resolved CB

    (@cbrandt)


    Hi,

    Certain plugins that depend on the REST API, such as Redirection, stopped working properly after I installed PWA. My caching plugin is set not to cache /wp-json/*, but somehow several URLs starting with /wp-json/ are being served by the SW instead of being fetched from the origin server. Is this expected behavior? I use Cloudflare, but it is respecting the http headers and therefore not caching these URLs either.

    EDIT: Please see this screenshot.

    Thanks

    • This topic was modified 1 month, 4 weeks ago by  CB.
    • This topic was modified 1 month, 4 weeks ago by  CB.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Jose Varghese 元

    (@josevarghese)

    Hey there,

    Good day to you. If you would like to exclude the caching of wp-json please copy the below code into functions.php

    /**
     * Exclude wp-json from SuperPWA cache
     * 
     * @link https://superpwa.com/codex/superpwa_sw_never_cache_urls/
     */
    function superpwa_exclude_from_cache( $superpwa_sw_never_cache_urls ) {
    	return $superpwa_sw_never_cache_urls . ',/\/wp-json/;
    }
    add_filter( 'superpwa_sw_never_cache_urls', 'superpwa_exclude_from_cache' );

    After that clear the browsing data and try again. It will surely help you.

    Don’t forget to clear the cache, if any CDN, caching plugins are used.

    Looking forward.

    Hi Jose,

    Thanks for the prompt reply.

    The code is not working, though. I’m not a developer but it seems there’s a ' missing right before ;, right?, but even after that is fixed it does not prevent SW from caching wp-json. I did all the cache purging, even turned caching off while I try to fix this.

    Plugin Author Jose Varghese 元

    (@josevarghese)

    Sorry, it was my mistake. Yes, you’re absolutely right. Have you cleared the browsing data before testing?

    Also if you don’t mind can you please share the website URL, so that I can test the same at my end.

    Looking forward.

    Thank you, Jose.

    Somehow after a couple hours things started working as expected. I checked “Update on reload” on Chrome DevTools > Application > Service Workers, then reloaded the page a couple of times. It didn’t seem to have worked at first, so perhaps my hosting has some sort of server-level cache, that may be causing this.

    • This reply was modified 1 month, 4 weeks ago by  CB.
    Plugin Author Jose Varghese 元

    (@josevarghese)

    Awesome!! Good to hear that.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.