Browse Source

HUE-6643 [frontend] Enable caching of Ajax calls when loading external files in Hue 4

Enrico Berti 8 years ago
parent
commit
6cffd12
1 changed files with 6 additions and 0 deletions
  1. 6 0
      desktop/core/src/desktop/templates/hue.mako

+ 6 - 0
desktop/core/src/desktop/templates/hue.mako

@@ -696,7 +696,9 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
           var jsFile = $el.attr('src').split('?')[0];
           var jsFile = $el.attr('src').split('?')[0];
           if (loadedJs.indexOf(jsFile) === -1) {
           if (loadedJs.indexOf(jsFile) === -1) {
             loadedJs.push(jsFile);
             loadedJs.push(jsFile);
+            $.ajaxSetup({ cache: true });
             $el.clone().appendTo($('head'));
             $el.clone().appendTo($('head'));
+            $.ajaxSetup({ cache: false });
           }
           }
           $el.remove();
           $el.remove();
         });
         });
@@ -705,7 +707,9 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
           var cssFile = $el.attr('href').split('?')[0];
           var cssFile = $el.attr('href').split('?')[0];
           if (loadedCss.indexOf(cssFile) === -1) {
           if (loadedCss.indexOf(cssFile) === -1) {
             loadedCss.push(cssFile);
             loadedCss.push(cssFile);
+            $.ajaxSetup({ cache: true });
             $el.clone().appendTo($('head'));
             $el.clone().appendTo($('head'));
+            $.ajaxSetup({ cache: false });
           }
           }
           $el.remove();
           $el.remove();
         });
         });
@@ -717,9 +721,11 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
         // Only load CSS and JS files that are not loaded before
         // Only load CSS and JS files that are not loaded before
         self.processHeaders = function(response){
         self.processHeaders = function(response){
           var r = $('<span>').html(response);
           var r = $('<span>').html(response);
+          % if conf.DJANGO_DEBUG_MODE.get():
           r.find('link').each(function () {
           r.find('link').each(function () {
             $(this).attr('href', $(this).attr('href') + '?' + Math.random())
             $(this).attr('href', $(this).attr('href') + '?' + Math.random())
           });
           });
+          % endif
           r.find('script[src]').each(function () {
           r.find('script[src]').each(function () {
             huePubSub.publish('hue4.add.global.js', $(this));
             huePubSub.publish('hue4.add.global.js', $(this));
           });
           });