JakeChampion / fetch

A window.fetch JavaScript polyfill.

Home Page:http://github.github.io/fetch/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

suggestion to use str.indexOf(searchString) === 0 for better compatibility

elasim opened this issue · comments

According to caniuse, the browser coverage for the fetch API is similar to the support range for String.prototype.startsWith,
which suggests that browsers requiring a fetch polyfill would likely also need a polyfill for the startsWith API.

Therefore, it would be advisable to use str.indexOf(searchString) === 0 instead of startsWith in the code for better compatibility across browsers

image

fetch/fetch.js

Lines 544 to 550 in b5cee50

// This check if specifically for when a user fetches a file locally from the file system
// Only if the status is out of a normal range
if (request.url.startsWith('file://') && (xhr.status < 200 || xhr.status > 599)) {
options.status = 200;
} else {
options.status = xhr.status;
}

I'll happily accept a pull request if you are up for submitting one

@elasim Good point 👍