3

I localized an Angular App with the standard Angular localize package. That works perfect and I host my app on firebase. I read the firebase article on how to configure i18n rewrites and implemented it in my firebase.json(https://firebase.google.com/docs/hosting/i18n-rewrites). The french version is loaded when .../fr, russian one for .../ru depending on the language preference of the user's browser and as a default .../en for English. The rewrite also works as expected.

I also want to enable the user to save their preference and that should be possible by setting
document.cookie = "firebase-language-override=fr"

However, it seems like the cookie is completely ignored and firebase still serves whatever the user's preference is.

Any experience or suggestion what I can do about it? Are there other ways to change the firebase rewrite behavior?

Flowmerca
  • 165
  • 1
  • 5

1 Answers1

2

The problem is most likely related to cache control. When the client loads the page for the first time, it is cached for an hour (by default) and even if you change the cookie, requesting the same page will give you cached result back (the result that is based on initial conditions - user language settings or cookie override).

You can test this by disabling cache in dev tools Network tab.

To solve the problem, try updating cache-control for default routes in your firebase.json:

{
  "headers": [
      {
        "source": "/",
        "headers": [
          {
            "key": "Cache-Control",
            "value": "no-store"
          }
        ]
      }
    ]
 }
zhendalf
  • 56
  • 4