Skip to content

Commit c5abe2d

Browse files
Rollup merge of rust-lang#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``
2 parents 3cda519 + 87b6326 commit c5abe2d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/librustdoc/html/static/js/main.js

+3
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ function loadCss(cssFileName) {
303303
getSettingsButton().onclick = event => {
304304
addClass(getSettingsButton(), "rotate");
305305
event.preventDefault();
306+
// Sending request for the CSS and the JS files at the same time so it will
307+
// hopefully be loaded when the JS will generate the settings content.
308+
loadCss("settings");
306309
loadScript(window.settingsJS);
307310
};
308311

src/librustdoc/html/static/js/settings.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* eslint prefer-const: "error" */
44
/* eslint prefer-arrow-callback: "error" */
55
// Local js definitions:
6-
/* global getSettingValue, getVirtualKey, updateLocalStorage, updateSystemTheme, loadCss */
6+
/* global getSettingValue, getVirtualKey, updateLocalStorage, updateSystemTheme */
77
/* global addClass, removeClass, onEach, onEachLazy, NOT_DISPLAYED_ID */
88
/* global MAIN_ID, getVar, getSettingsButton, switchDisplayedElement, getNotDisplayedElem */
99

@@ -209,9 +209,6 @@
209209
},
210210
];
211211

212-
// First, we add the settings.css file.
213-
loadCss("settings");
214-
215212
// Then we build the DOM.
216213
const el = document.createElement("section");
217214
el.id = "settings";

0 commit comments

Comments
 (0)