• Resolved lexvz

    (@lexvz)


    Hi there,

    I am – very happily – using Optimole to optimize my images that I fetch through the WordPress REST API. Unfortunately, when I try to cache the REST API requests, the image URL no longer refers to Optimole’s server(s), but it refers to the default image URL.

    Normally, the REST API response has ‘adapted’ image URL’s that refer to Optimole servers. I guess they change the API response dynamically upon requesting it, but that is not included in the cache.

    Do you have any idea perhaps what I could do here? I’ve asked the Optimole plugin creator as well, but I do not really know how to tweak both to work better together.

    Thanks in advance!

    Best,
    Lex

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Richard Korthuis

    (@rockfire)

    Hi @lexvz

    Thank you for using our plugin!

    I have investigated the Optimole plugin in order to understand what is causing this issue. What they do is they use the output buffer to replace all url’s in the output of the REST API. The output buffer however is really low-level PHP, which means there are no other WordPress hooks after it where we can hook into to cache the results.

    We do our caching on the rest_pre_echo_response hook provided by WordPress (https://developer.www.ads-software.com/reference/hooks/rest_pre_echo_response/), this is done prior to the output buffer replacement of Optimole. So we cache the REST results before they have replaced their url’s. Now when you do the same REST call we return the results, which is done before any plugin is activated, so their url replacement isn’t done when we output the cache, resulting in you seeing the url’s before replacement.

    So the best solution would be for Optimole to hook into rest_pre_echo_response prior to us and replacing the url’s at that moment. That way the correct url’s are cached and the issue is solved. I have found your support topic with their plugin and will respond there too.

    Thread Starter lexvz

    (@lexvz)

    @rockfire, thanks a million for doing such thorough research on this. Much appreciated!

    I will do some tests trying to adapt Optimole in such a way that it hooks into the rest_pre_echo_response and I’ll try to see whether they can help out too.

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Caching with Optimole image optimisation’ is closed to new replies.