i18next / i18next-xhr-backend

[deprecated] can be replaced with i18next-http-backend
https://github.com/i18next/i18next-http-backend
MIT License
253 stars 75 forks source link

add support for fetch() API #339

Closed MagicalTux closed 4 years ago

MagicalTux commented 4 years ago

Adding support for modern fetch() api through the existing ajax() method and keeping compatibility as much as possible.

jamuhl commented 4 years ago

Not 100% what the benefit of adding this is? Could you explain? Without further explanation, it looks like adding code to use a newer feature for the sake of using a newer API...or is there a benefit I miss?

MagicalTux commented 4 years ago

Most people doing SSR (like we are doing) do not have XMLHttpRequest. There are polyfills existing (see https://www.npmjs.com/package/xmlhttprequest for example) however most browsers (except IE11) also support the newer fetch() API, which has a cleaner API in general in order to define passing credentials/cors/etc.

Ideally the whole thing should be rewritten to use fetch() syntax and fallback to XMLHttpRequest in rare cases when fetch() is unavailable (or use a polyfill for fetch()), however I wanted to keep changes localized and with a minimal impact.

jamuhl commented 4 years ago

there is already an alternative: https://github.com/perrin4869/i18next-fetch-backend

julianwachholz commented 4 years ago

or is there a benefit I miss?

For a PWA with offline-first approach all offline-capable resources need to be loaded with fetch, XHR is not compatible. Right now my app is using i18next-xhr-backend and this breaks the offline capability of the rest of the app when the device has no service.

jamuhl commented 4 years ago

@julianwachholz still there is: https://github.com/perrin4869/i18next-fetch-backend for that case