• Resolved nguyennhuttien

    (@nguyennhuttien)


    I use both EWWW Image Optimizer plugin and WP Offload Media Lite to generate webp format for upload image and offload to S3. I choose JS Webp Rewriting option to deliver webp format to my site and it works well. But when I call WP rest api : https://domain.com/wp-json/wp/v2/posts?_embed&slug=this-is-post-slug (GET), it just returns jpg/png format, not webp. I expect it returns webp such as JS Webp Rewriting do with my site. Is there any options on EWWW Image Optimizer plugin to setting or I need to custom manually somewhere in my source code?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author nosilver4u

    (@nosilver4u)

    JS WebP is explicitly disabled for embeds, because we don’t know where the content will be displayed. Embeds are usually for display on other sites, and they may or may not have the JS code to correctly handle the HTML markup that we use. That would just give you broken images, and we don’t want that ??

    If you have control over the destination site, you could create your own parser using the EIO_Alt_Webp class, but you’d have to be careful there also, as embeds tend to be used for Facebook (and other social media) previews–though I don’t recall off-hand if it’s that exact endpoint which gets used. And of course, then you’d have to load our JS on the destination site too, so that the HTML can be wrangled back into shape.

    Thread Starter nguyennhuttien

    (@nguyennhuttien)

    Hi @nosilver4u ,
    How about https://domain.com/wp-json/wp/v2/posts?slug=this-is-post-slug (GET)
    which is not embeds ? It returns response:

    [
        {
            "id": 1234,
            "date": "2021-05-20T15:04:20",
            ...
            ...
            "content": {
                "rendered": "......."

    The text in “rendered” is the content of the post. My partner gets it and display on other site, and images just has jpeg/png, not webp. I expected it has webp.
    And I realize other problem: when I open the post by clicking view https://domain.com/slug-of-post, images has webp, but when I open the post by clicking preview https://domain.com/slug-of-post/?preview_id=11130&preview_nonce=08c6efb2d6&preview=true&_thumbnail_id=11045, images not webp, it is jpeg/png.

    Because I couldn’t find any document about serve webp on wordpress rest api and I have no knowledge about “create your own parser using the EIO_Alt_Webp class,” as you mentioned, so I try to describe the problem in detail in the hope that you can come up with an easier solution.

    Plugin Author nosilver4u

    (@nosilver4u)

    Can you please post the debug information from the settings page via pastebin.com?

    Thread Starter nguyennhuttien

    (@nguyennhuttien)

    Plugin Author nosilver4u

    (@nosilver4u)

    The best way to deliver WebP images across domains like that is with server-based WebP rewriting. And since you don’t know how to write your own parser, it’s really the only way.

    Based on the debug info, you’re using Amazon S3 for your images, thus .htaccess or Nginx rules are not possible. So the only ways I know to make server-based rewriting happen are:
    1. Cloudflare (Pro) with a custom CNAME for your S3 bucket/Cloudfront.
    2. Our Easy IO service, which I’ve verified does work for REST API responses.
    3. Any other CDN that has image optimization with WebP conversion built-in.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to deliver webp format to WP REST API’ is closed to new replies.