mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-24 00:38:31 +08:00
Pre-fetch the config.json to improve startup time
This commit is contained in:
parent
9650ca9687
commit
2e172aa3be
@ -8,7 +8,7 @@ server {
|
|||||||
|
|
||||||
location / {
|
location / {
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
add_header Cache-Control "no-store, no-cache, must-revalidate";
|
add_header Cache-Control "public, max-age=30, stale-while-revalidate=30";
|
||||||
}
|
}
|
||||||
|
|
||||||
# assets can be cached because they have hashed filenames
|
# assets can be cached because they have hashed filenames
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="favicon.png" />
|
<link rel="icon" type="image/svg+xml" href="favicon.png" />
|
||||||
|
<link rel="preload" href="/config.json" as="fetch" />
|
||||||
<meta
|
<meta
|
||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0"
|
content="width=device-width, initial-scale=1.0, maximum-scale=1.0"
|
||||||
|
@ -28,11 +28,11 @@ export class Config {
|
|||||||
const internalInstance = new Config();
|
const internalInstance = new Config();
|
||||||
Config.internalInstance = internalInstance;
|
Config.internalInstance = internalInstance;
|
||||||
|
|
||||||
Config.internalInstance.initPromise = downloadConfig(
|
Config.internalInstance.initPromise = downloadConfig("/config.json").then(
|
||||||
"../config.json",
|
(config) => {
|
||||||
).then((config) => {
|
internalInstance.config = merge({}, DEFAULT_CONFIG, config);
|
||||||
internalInstance.config = merge({}, DEFAULT_CONFIG, config);
|
},
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
return Config.internalInstance.initPromise;
|
return Config.internalInstance.initPromise;
|
||||||
}
|
}
|
||||||
@ -74,11 +74,7 @@ async function downloadConfig(
|
|||||||
configJsonFilename: string,
|
configJsonFilename: string,
|
||||||
): Promise<ConfigOptions> {
|
): Promise<ConfigOptions> {
|
||||||
const url = new URL(configJsonFilename, window.location.href);
|
const url = new URL(configJsonFilename, window.location.href);
|
||||||
url.searchParams.set("cachebuster", Date.now().toString());
|
const res = await fetch(url);
|
||||||
const res = await fetch(url, {
|
|
||||||
cache: "no-cache",
|
|
||||||
method: "GET",
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!res.ok || res.status === 404 || res.status === 0) {
|
if (!res.ok || res.status === 404 || res.status === 0) {
|
||||||
// Lack of a config isn't an error, we should just use the defaults.
|
// Lack of a config isn't an error, we should just use the defaults.
|
||||||
|
Loading…
Reference in New Issue
Block a user