For the complete documentation index, see llms.txt. This page is also available as Markdown.

Caching

Browser caching with local storage

With i18next you can configure a cache layer to be used in the browser. It will load and cache resources from localStorage and can be used in combination with the chained backend.

import i18next from "i18next";
import ChainedBackend from "i18next-chained-backend";
import HttpBackend from "i18next-http-backend";
import LocalStorageBackend from "i18next-localstorage-backend";

i18next
  .use(ChainedBackend)
  .init({
    fallbackLng: "en",
    // ... your i18next config
    backend: {
      backends: [
        LocalStorageBackend,
        HttpBackend
      ],
      backendOptions: [{
        expirationTime: 7 * 24 * 60 * 60 * 1000 // 7 days
      }, {
        loadPath: '/locales/{{lng}}/{{ns}}.json'
      }]
    }
  });

Server side caching with filesystem

With i18next you can configure a cache layer to be used on server side. It will load and cache resources from the filesystem and can be used in combination with the chained backend.

React-native caching with AsyncStorage

With i18next you can configure a cache layer to be used on react-native. It will load and cache resources from the AsyncStorage and can be used in combination with the chained backend.

Next.js caching with next-i18next

With next-i18next v16+, you can use client-side caching with i18next-chained-backend and i18next-localstorage-backend. Translations are bundled at build time (via resourceLoader for App Router or serverSideTranslations for Pages Router), and the client can fetch fresh translations from a backend with localStorage caching.

For a complete example using both App Router and Pages Router with Locize, have a look at the next-i18next-locize example.

App Router (client-side caching with Locize)

Pages Router (client-side caching with Locize)

Last updated