From 0bd5fe8759c01f051aa9d73d60a5181ac4e7c111 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Wed, 26 Jul 2017 12:52:40 +0100 Subject: [PATCH] Only show busy favicon when execution lasts > 1s This avoids making lots of HTTP requests as we rapidly change the favicon between the 'notebook' (idle) and 'busy' icons. Now it should be no more than one per second in the most pathological case. Closes gh-2673 --- notebook/static/base/js/utils.js | 4 ++++ notebook/static/notebook/js/notificationarea.js | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/notebook/static/base/js/utils.js b/notebook/static/base/js/utils.js index 17ccc8e72..af1ad2d7a 100644 --- a/notebook/static/base/js/utils.js +++ b/notebook/static/base/js/utils.js @@ -1103,6 +1103,10 @@ define([ link.type = 'image/x-icon'; link.rel = 'shortcut icon'; link.href = utils.url_path_join(utils.get_body_data('baseUrl'), src); + if (link.href === oldLink.href) { + // This favicon is already set, don't modify the DOM. + return; + } if (oldLink) document.head.removeChild(oldLink); document.head.appendChild(link); }; diff --git a/notebook/static/notebook/js/notificationarea.js b/notebook/static/notebook/js/notificationarea.js index bbcb46a5c..ed183db42 100644 --- a/notebook/static/notebook/js/notificationarea.js +++ b/notebook/static/notebook/js/notificationarea.js @@ -42,11 +42,19 @@ define([ var $modal_ind_icon = $("#modal_indicator"); var $readonly_ind_icon = $('#readonly-indicator'); var $body = $('body'); + var busy_favicon_timer = -1; var set_busy_favicon = function(on) { if (on) { - utils.change_favicon('/static/base/images/favicon-busy-1.ico'); + // Only show the busy icon if execution lasts > 1s + // This is to avoid rapidly switching icons and making lots of + // HTTP requests. + clearTimeout(busy_favicon_timer); + busy_favicon_timer = setTimeout(function() { + utils.change_favicon('/static/base/images/favicon-busy-1.ico'); + }, 1000); } else { + clearTimeout(busy_favicon_timer); utils.change_favicon('/static/base/images/favicon-notebook.ico'); } };