about summary refs log tree commit diff
path: root/src/librustdoc/html/static
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-05-05 19:34:25 -0700
committerGitHub <noreply@github.com>2022-05-05 19:34:25 -0700
commit7cdad775363e5c4b723870ecfcd091ee1a13a9dd (patch)
tree1c53ca2994bd2c18b7b1586b96805463003774d1 /src/librustdoc/html/static
parentb78179e1f7e48c0a44664435fecada88425e6042 (diff)
parent87b6326d672f5d40b14460bdedebf4f69288fb6a (diff)
downloadrust-7cdad775363e5c4b723870ecfcd091ee1a13a9dd.tar.gz
rust-7cdad775363e5c4b723870ecfcd091ee1a13a9dd.zip
Rollup merge of #96741 - GuillaumeGomez:improve-settings-loading-strategy, r=jsha
Improve settings loading strategy

I learned about this thanks to ```@jsha``` who suggested this approach:

It improves the settings loading strategy by loading CSS and JS at the same time to prevent the style to be applied afterwards on slow connections.

r? ```@jsha```
Diffstat (limited to 'src/librustdoc/html/static')
-rw-r--r--src/librustdoc/html/static/js/main.js3
-rw-r--r--src/librustdoc/html/static/js/settings.js5
2 files changed, 4 insertions, 4 deletions
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js
index e8edd5f2d23..66a7d484f33 100644
--- a/src/librustdoc/html/static/js/main.js
+++ b/src/librustdoc/html/static/js/main.js
@@ -303,6 +303,9 @@ function loadCss(cssFileName) {
     getSettingsButton().onclick = event => {
         addClass(getSettingsButton(), "rotate");
         event.preventDefault();
+        // Sending request for the CSS and the JS files at the same time so it will
+        // hopefully be loaded when the JS will generate the settings content.
+        loadCss("settings");
         loadScript(window.settingsJS);
     };
 
diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js
index d1526270f30..e447d09ab6b 100644
--- a/src/librustdoc/html/static/js/settings.js
+++ b/src/librustdoc/html/static/js/settings.js
@@ -3,7 +3,7 @@
 /* eslint prefer-const: "error" */
 /* eslint prefer-arrow-callback: "error" */
 // Local js definitions:
-/* global getSettingValue, getVirtualKey, updateLocalStorage, updateSystemTheme, loadCss */
+/* global getSettingValue, getVirtualKey, updateLocalStorage, updateSystemTheme */
 /* global addClass, removeClass, onEach, onEachLazy, NOT_DISPLAYED_ID */
 /* global MAIN_ID, getVar, getSettingsButton, switchDisplayedElement, getNotDisplayedElem */
 
@@ -209,9 +209,6 @@
             },
         ];
 
-        // First, we add the settings.css file.
-        loadCss("settings");
-
         // Then we build the DOM.
         const el = document.createElement("section");
         el.id = "settings";