]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5334 Fix performance issue with localStorage on Safari
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 2 Jul 2014 09:41:02 +0000 (11:41 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 2 Jul 2014 09:41:09 +0000 (11:41 +0200)
sonar-server/src/main/js/translate.js

index 8dc0ba939216e5b325a396689151d04475177248..0681b727d4625c6d46e4be4d447989ea4e320ab8 100644 (file)
       dataType: 'json',
       statusCode: {
         304: function() {
-          // NOP, use cached messages
+          window.messages = JSON.parse(localStorage.getItem('l10n.bundle'));
         }
       }
     }).done(function(bundle) {
-      bundleTimestamp = new Date().toISOString();
-      bundleTimestamp = bundleTimestamp.substr(0, bundleTimestamp.indexOf('.')) + '+0000';
-      localStorage.setItem('l10n.timestamp', bundleTimestamp);
-      localStorage.setItem('l10n.locale', currentLocale);
+      if(bundle !== undefined) {
+        bundleTimestamp = new Date().toISOString();
+        bundleTimestamp = bundleTimestamp.substr(0, bundleTimestamp.indexOf('.')) + '+0000';
+        localStorage.setItem('l10n.timestamp', bundleTimestamp);
+        localStorage.setItem('l10n.locale', currentLocale);
 
-      for (var message in bundle) {
-        if (bundle.hasOwnProperty(message)) {
-          var storageKey = 'l10n.' + message;
-          localStorage.setItem(storageKey, bundle[message]);
-        }
+        window.messages = bundle;
+        localStorage.setItem('l10n.bundle', JSON.stringify(bundle));
       }
     });
   };
-
 })();