From 5d128505dca854cb7225624936d1053f06473260 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Aug 2018 11:39:58 +0200 Subject: [PATCH] Cache player translations --- client/src/assets/player/peertube-player.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/client/src/assets/player/peertube-player.ts b/client/src/assets/player/peertube-player.ts index 0b9303a73..7e53d2142 100644 --- a/client/src/assets/player/peertube-player.ts +++ b/client/src/assets/player/peertube-player.ts @@ -184,11 +184,24 @@ function loadLocaleInVideoJS (serverUrl: string, videojs: any, locale: string) { // It is the default locale, nothing to translate if (!path) return Promise.resolve(undefined) - const completeLocale = getCompleteLocale(locale) + let p: Promise + + if (loadLocaleInVideoJS.cache[path]) { + p = Promise.resolve(loadLocaleInVideoJS.cache[path]) + } else { + p = fetch(path + '/player.json') + .then(res => res.json()) + .then(json => { + loadLocaleInVideoJS.cache[path] = json + return json + }) + } - return fetch(path + '/player.json') - .then(res => res.json()) - .then(json => videojs.addLanguage(getShortLocale(completeLocale), json)) + const completeLocale = getCompleteLocale(locale) + return p.then(json => videojs.addLanguage(getShortLocale(completeLocale), json)) +} +namespace loadLocaleInVideoJS { + export const cache: { [ path: string ]: any } = {} } function getServerTranslations (serverUrl: string, locale: string) { -- 2.25.1