libpalaso
libpalaso copied to clipboard
Improve how SLDR downloads langtag.json file
When SLDR is initialized, it currently does a synchronous request to download the langtags.json file and this request can be slow on machines with slow internet connections.
It would be better if the download of the langtags.json file could be separated out from the initialization code and allow applications to decide when to make the call.
Also, the SLDR code currently uses the IF-MODIFIED-SINCE header and for a while this was broken on the server. It is working now, but WSTech would like us to switch to using the ETag method instead since this is now more common. They gave this as a reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
It would be better if the download of the langtags.json file could be separated out from the initialization code and allow applications to decide when to make the call.
@jwickberg Don't we have that already? There's Sldr.InitializeLanguageTags()
which does the download of langtags.json
. The application can decide when that gets called. If it has been called before (i.e. if _languageTags
is not null) we won't do the download again. Or do you mean that we should always use the local langtags.json
file, and do the download in a separate method that the application can call when it pleases to do so?
@ermshiperete I created this when I found that Paratext was starting slowly on some machines because of the download of the langtags.json file - this was made worse because the IF-MODIFIED-SINCE wasn't working which meant the file was always being downloaded. That was corrected on the server, but WSTech suggested we do the check a different way. If we are sure that the timestamp check is working - the flag is less important. Probably need to check with WSTech again to see the best way to make sure that the timestamp works.
I think what needs to happen:
- extract downloading code to a new public method
- change signature of
Sldr.InitializeLanguageTags()
toSldr.InitializeLanguageTags(bool downloadLangTags = true)
and call the new download method only ifdownloadLangTags
istrue
. This deserves a+semver:major
in the commit message (and an entry inCHANGELOG.md
). - change download method to use ETag (IF-NONE-MATCH header) instead of IF-MODIFIED-SINCE header. This requires a way to store the ETag of the downloaded file somewhere, maybe in a separate file (
langtags.json.etag
). Downloading should re-populate_languageTags
.