chore: embed build info in the html to reduce requests (#6605)

This will reduce a request on every page load of Coder!
This commit is contained in:
Kyle Carberry
2023-03-21 19:04:54 +00:00
committed by GitHub
parent 74be9c6c55
commit 71eecb3515
3 changed files with 39 additions and 9 deletions
@@ -53,7 +53,20 @@ export const buildInfoMachine = createMachine(
},
{
services: {
getBuildInfo: API.getBuildInfo,
getBuildInfo: async () => {
// Build info is injected by the Coder server into the HTML document.
const buildInfo = document.querySelector("meta[property=build-info]")
if (buildInfo) {
const rawContent = buildInfo.getAttribute("content")
try {
return JSON.parse(rawContent as string)
} catch (ex) {
// Ignore this and fetch as normal!
}
}
return API.getBuildInfo()
},
},
actions: {
assignBuildInfo: assign({