question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extra HTTP requests

See original GitHub issue

🐛 Bug Report

After loading the web application, an http request goes out to get localization data from *loadPath. If you change the current language, then the corresponding files will come from the backend - this behavior is quite logical,because I only get files that will use.

Folders structure

- public/
--- locales/
----- ru
------- translation.json
------- filters.json
----- ua
------- translation.json
------- filters.json

correct

In i18n options I also use LanguageDetector, which helps me to save the current state of the language in local storage (init file below)

i18n
  .use(Backend)
  .use(LanguageDetector)
  .use(initReactI18next)
  .init({
    initImmediate: false,
    fallbackLng: 'ru',
    debug: isDebugMode,
    ns: ['filters'],
    defaultNS: 'translation',
    interpolation: {
      escapeValue: false,
      formatSeparator: ','
    },
    react: {
      wait: true,
      useSuspense: true
    },
    backend: {
      loadPath: './locales/{{lng}}/{{ns}}.json' // * where i store my locales
    },
    detection: {
      order: ['localStorage'],
      caches: ['localStorage', 'cookie'],
      cookieMinutes: 80
    }
  })

Further, after switching the language and reloading the page, I will receive a json that corresponds to the current language. But there will also be extra requests to get localization files that should not be used

wrong *red dots mark unnecessary requests

To Reproduce

In other words. I ran the page for the first time and got the files corresponding to ‘fallbackLng’ - from locales/ru/* Then I changed the language to ua, the changes were saved in localStorage, and after reboot, I hope to only get the files from locales/ua/*. But in the end I get files from both directories

Expected behavior

After changing the language and reloading the page, I want to receive those files that correspond to the current language, avoiding unnecessary requests

Your Environment

  • runtime version: browser -> react-i18next v11.3.4
  • i18next version: 19.3.4
  • os: Windows / Mac

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:22 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
Vlad-Shevliakovcommented, Feb 19, 2021

I think yes

1reaction
Vlad-Shevliakovcommented, Feb 17, 2021

Well. I will reinstall all my libraries, re-read the documentation again and try to figure out the cause of this problem. Perhaps this problem is from my side. Probably should close this issue?

Thank you very much for your help and for 3 hours of your time!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular/RxJS 6: How to prevent duplicate HTTP requests?
After trying a few different methods, I came across this one that resolves my issue and only makes one HTTP request no matter...
Read more >
Avoiding Angular duplicate HTTP requests with the RxJs ...
Currently I have an HTTP call - RetrieveUserFromServer, which takes the data retrieved from the server and updates a ReplaySubject in the service....
Read more >
How to add extra HTTP Request Headers to Custom Tab Intents
Guide for adding HTTP CORS headers in Custom Tab Intents.
Read more >
HTTP Messages - MDN Web Docs - Mozilla
HTTP requests are messages sent by the client to initiate an action ... HTTP/2 introduces an extra step: it divides HTTP/1.x messages into ......
Read more >
How to block duplicated HTTP request at the same second on ...
If your APIs have heterogeneous payloads and you believe you can create a generic treatment for all your HTTP requests, you can use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found