easy_localization icon indicating copy to clipboard operation
easy_localization copied to clipboard

JSON files not updating in Flutter web due to browser cache

Open jacksilver2 opened this issue 4 years ago • 6 comments

The browser caches json files because they are loaded without a ?v=x.x query string. This means that the cache needs to be emptied when a change is made which is highly problematic.

jacksilver2 avatar Dec 27 '20 11:12 jacksilver2

@jacksilver2 thanks, thanks for issue, if you have a solution you can do a PR, it will help the project 😉

Overman775 avatar Jan 10 '21 20:01 Overman775

Hey guys, I'm just looking for a new localization variant for my productive application and I'm struggling with exactly this behaviour.

After an update of my web app, including increasing the version number in the index.html file <script src="main.dart.js?version=xxx" type="application/javascript"></script>, the users have to empty their browser cache to load the changed .json translations.

Can easy_localization handle this behaviour better? Thanks!

Aerofluxx avatar Apr 12 '21 09:04 Aerofluxx

Does someone has a solution?

TungWang avatar Jun 18 '21 03:06 TungWang

Same problem. Does anyone have a workaround?

kasyr avatar Aug 25 '21 13:08 kasyr

If you use easy_localization generate feature you don't have this issue anymore since your lang files are generated in your dart code

Generates the lang file : flutter pub run easy_localization:generate --source-dir ./assets/languages -O lib/languages

Generates the key file : flutter pub run easy_localization:generate --source-dir ./assets/languages -O lib/languages -o locale_keys.g.dart -f keys

Add assetLoader to your EasyLocalization config

void main(){
  runApp(EasyLocalization(
    child: MyApp(),
    supportedLocales: [Locale('en', 'US'), Locale('ar', 'DZ')],
    path: 'resources/langs',
    assetLoader: CodegenLoader()
  ));
}

Add a translation in a widget : Text(LocaleKeys.title.tr())

TheSmartMonkey avatar Apr 13 '22 13:04 TheSmartMonkey

@TheSmartMonkey thanks a lot for this input, will try this very soon and come back to this topic.

Aerofluxx avatar Apr 13 '22 13:04 Aerofluxx