Leo Jiang
Leo Jiang

Reputation: 26085

Is it possible to use JS to check which encoding schemes are supported, without hitting a server?

Due to a poorly configured CDN that I don't have control over, I can't access the accept-encoding header from the server. Is it possible for client-side JS to determine which encoding schemes (gzip, br) are supported? Then, I can make requests like <script src="/script.js?encodings=gzip,br">

Upvotes: 2

Views: 139

Answers (1)

Leo Jiang
Leo Jiang

Reputation: 26085

For now, I did:

var supportsBrotli = window.Symbol && Symbol.hasInstance && Symbol.toPrimitive && window.WebAssembly;
document.getElementById('script').src = '/js/script.js' + (supportsBrotli ? '.br' : '');

Those JS methods are from caniuse, it should work for Chrome, FF, and Safari.

Upvotes: 1

Related Questions