0

I've a use case where I need to get files from a CDN but I need to know what encodings does the browser support in order to append the right file extension on the files to get.

Is there a way to query the DOM or the browser about its support of encodings?

Eugene
  • 217
  • 8
  • 24
  • 1
    "*in order to append the right file extension*" - no. The whole idea of the `Accept-Encoding` header is that the server responds with a resource in the appropriate format. Not for the client having to choose. – Bergi Feb 05 '23 at 15:15
  • @Bergi well, the thing is that CDNs are general purpose and the one that I have to use I can't force it into any such logic about my uploaded files so I need to be the one providing the right files to request. – Eugene Feb 05 '23 at 15:19
  • Then I'd suggest to use your own backend server to decode the `Accept-Encoding` header and redirect the client to the respective file based on that. – Bergi Feb 05 '23 at 15:24
  • Btw, what kind of files are we talking about here, and what encodings do you have that you expect some browsers not to support? Not sure I understand your usecase yet. – Bergi Feb 05 '23 at 15:25
  • @Bergi gzip and brotli are currently taken into consideration and supported. I guess I'll go with a custom endpoint to ping for such info. Feel free to leave that solution as an answer given that there's no better way to get that info from JavaScript alone. – Eugene Feb 05 '23 at 19:05
  • I'm pretty certain that you cannot access it from JS, other than by asking an echo server for the value of the header that the browser is sending. But really, the compression algorithm is something that the CDN server should take care of, nothing you need to deal with yourself. What CDN is it? – Bergi Feb 05 '23 at 20:10
  • @Bergi BunnyCDN – Eugene Feb 05 '23 at 21:04
  • According to https://bunny.net/blog/how-bunnycdn-shredded-the-size-of-your-text-files-by-10-20-with-brotli/, BunnyCDN supports Brotli [for HTTP compression](https://bunny.net/academy/http/what-is-http-compression/) since 2018. I'm certain it is applied to [these file types](https://support.bunny.net/hc/en-us/articles/115001200111-Which-MIME-types-does-BunnyCDN-gzip-). – Bergi Feb 05 '23 at 22:49
  • But anyway, the http compression has nothing to do with the file extension. Even if you could detect the supported algorithms from JS, there would be no way to control it by pointing the browser at different URLs - the server still would need to be able to use the http compression or not. – Bergi Feb 05 '23 at 22:51
  • The "file extension" could be remotely related to the [`Accept`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept) and [`Content-Type`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type) headers at best – Bergi Feb 05 '23 at 22:54
  • @Bergi ".dll,.pdb,.wasm,.blat,.dat" this are definitely not covered as a mime type, so I guess I'm out of luck – Eugene Feb 06 '23 at 06:03
  • 1
    "*If you believe there is a type missing on our list, please feel free to contact us and we will consider adding.*" – Bergi Feb 06 '23 at 13:03

0 Answers0