Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure image requests send an accept header #8261

Closed
andrewharvey opened this issue May 19, 2019 · 0 comments · Fixed by #8262
Closed

ensure image requests send an accept header #8261

andrewharvey opened this issue May 19, 2019 · 0 comments · Fixed by #8262

Comments

@andrewharvey
Copy link
Collaborator

andrewharvey commented May 19, 2019

In modern browsers when you request an image if the browser supports webp it will add this to the request accept header, so if the server supports serving different content based on the client support it can.

However, when making a Fetch or XMLHttpRequest, the browser will pass */* as the accept header, in which case the server won't know if the client supports webp or not.

Mapbox raster sources have built in logic at

export const normalizeTileURL = function(tileURL: string, sourceURL?: ?string, tileSize?: ?number): string {
if (!sourceURL || !isMapboxURL(sourceURL)) return tileURL;
const urlObject = parseUrl(tileURL);
// The v4 mapbox tile API supports 512x512 image tiles only when @2x
// is appended to the tile URL. If `tileSize: 512` is specified for
// a Mapbox raster source force the @2x suffix even if a non hidpi device.
const suffix = browser.devicePixelRatio >= 2 || tileSize === 512 ? '@2x' : '';
const extension = webpSupported.supported ? '.webp' : '$1';
urlObject.path = urlObject.path.replace(imageExtensionRe, `${suffix}${extension}`);
urlObject.path = `/v4${urlObject.path}`;
return makeAPIURL(urlObject);
};
to ask for a webp tile when supported, but this change could help some 3rd party raster sources.

I've drafted a PR to address this at #8262

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant