f_auto based on accept http header

Comments

7 comments

  • Avatar
    Zachary Gould

    Hey there,
    For f_auto to work you need both the user_agent and accept headers.
    You can see for yourself by curling the address and setting your custom headers. Without the user_agent, the format will switch to default. 

    You can read more about f_auto in our documentation here

    Thanks!

    0
    Comment actions Permalink
  • Avatar
    youpigram

    Thanks for your answer! But:

    I can not reproduce the switch to default, when no user-agent header is present. In my tests with curl, an asset with the default type jpg is served as avif, if only the accept header is set.

    For example:

    curl -H "Accept: image/avif,image/webp,*/*" -H "User-Agent:" https://res.cloudinary.com/demo/image/upload/f_auto,q_auto,ar_16:7,c_fill,w_2560/sample.jpg --output sample.jpg

    Seems like there are exceptions to the rule you mention?

    And i know the docs you linked, but i can not find details, on how the format/browser detection exactly works, there.

    0
    Comment actions Permalink
  • Avatar
    Zachary Gould

    Hey there, 

    In your curl request, you are setting the `Accept` header to a series of file formats. If you leave those blank the file will default to jpeg. So with your curl request, you are including the `f_auto` param but not providing enough information for it to give you anything which sets the file format to .jpg, then you are superseding that by limiting the file types with your `Accept` header so you get .avif.    
    This is all to say that you can definitely change file types without `-H User-Agent` but for `f_auto` to work you will need it and provide at least some basic information like;

    Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36 
    0
    Comment actions Permalink
  • Avatar
    youpigram

    The "Accept" header in the curl example is the one, that the current version of firefox sends. And as this header states avif and webm is supported. And as i understand "f_auto", cloudinary chooses the smallest image format depending on what the browser supports (which is defined by the "Accept" header). So for example, depending on the image content, webp could be a better choice than avif. In this case cloudinary would send the webp, even if the "User-Agent" header is absent, because it is known through the "Accept" header that webp is also supported?

    And in combination with "q_auto" cloudinary would also include the visual quality of the image, when deciding which file format will be delivered.

    All this would work without a "User-Agent" header. Or what am i missing?

    Thanks for your patience, but i still don't get it.

    0
    Comment actions Permalink
  • Avatar
    Zachary Gould

    No problem, let me see if I can help you.

    So the example above is of the `User-Agent` header. This is what is populated by your browser and computer details. If you have no `User-Agent` header and use f_auto, Cloudinary will either default to jpeg or any file format specified in your `Accept` header. 
    You are correct in your understanding of `q_auto`. When used with f_auto, Cloudinary will choose the best file format and the best quality based on what your restrictions and needs are, hence why you need the `User-Agent` header. Otherwise, Cloudinary knows nothing of your OS, browser, or system, and would not be able to optimize anything to your specific needs.

    Please don't hesitate if you still have questions, I'm happy to help. 

    0
    Comment actions Permalink
  • Avatar
    youpigram

    You are correct in your understanding of `q_auto`. When used with f_auto, Cloudinary will choose the best file format and the best quality based on what your restrictions and needs are, ...

    So, as i understand it (and as a result of my testing), when only the `Accept` header is present, there is also some optimization. The quoted optimization is also possible (deciding between avif and webp based on visual quality for example), but other edge case optimizations only to an limited extend.

    And for the best possible optimization one would also need the "User-Agent" header. So edge cases in older browser versions (i.e. JPG 2000 on older mac/ios versions) can also be considered. In new browser versions, these exceptions become less relevant, i think. So in most cases (as far as i can tell as a result of my testing), there is no relevant difference (for my use cases), when the "User-Agent" header is omitted.

    Is there a list what optimizations for which user agents are made by cloudinary, so i could check my assumption?

    0
    Comment actions Permalink
  • Avatar
    Zachary Gould

    Hey there,
    Regardless of changes from the `Accept` header being set, while your file may change, it is not being optimized for your profile. You cannot achieve optimization unless you set the `User-Agent` header.
    Unfortunately, I can't share Cloudinary's optimization metrics because that's proprietary.

    I hope this helps.

    0
    Comment actions Permalink

Please sign in to leave a comment.