mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-20 07:46:37 +00:00
Preload (#6062)
This commit is contained in:
parent
78f5429c92
commit
aa9a354746
@ -5,18 +5,6 @@
|
||||
<link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />
|
||||
<link rel="icon" href="/static/icons/favicon.ico" />
|
||||
<link rel="mask-icon" href="/static/icons/mask-icon.svg" color="#03a9f4" />
|
||||
<link
|
||||
rel="preload"
|
||||
href="/static/fonts/roboto/Roboto-Regular.woff2"
|
||||
as="font"
|
||||
crossorigin
|
||||
/>
|
||||
<link
|
||||
rel="preload"
|
||||
href="/static/fonts/roboto/Roboto-Medium.woff2"
|
||||
as="font"
|
||||
crossorigin
|
||||
/>
|
||||
<link
|
||||
rel="apple-touch-icon"
|
||||
sizes="180x180"
|
||||
@ -96,6 +84,7 @@
|
||||
<div id="ha-init-skeleton"></div>
|
||||
<ha-demo></ha-demo>
|
||||
<%= renderTemplate('_js_base') %>
|
||||
<%= renderTemplate('_preload_roboto') %>
|
||||
|
||||
<script type="module" src="<%= latestDemoJS %>"></script>
|
||||
|
||||
|
@ -28,6 +28,7 @@ import { HomeAssistant } from "../types";
|
||||
declare global {
|
||||
interface Window {
|
||||
hassConnection: Promise<{ auth: Auth; conn: Connection }>;
|
||||
hassConnectionReady?: (hassConnection: Window["hassConnection"]) => void;
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,6 +83,11 @@ window.hassConnection = (authProm() as Promise<Auth | ExternalAuth>).then(
|
||||
connProm
|
||||
);
|
||||
|
||||
// This is set if app was somehow loaded before core.
|
||||
if (window.hassConnectionReady) {
|
||||
window.hassConnectionReady(window.hassConnection);
|
||||
}
|
||||
|
||||
// Start fetching some of the data that we will need.
|
||||
window.hassConnection.then(({ conn }) => {
|
||||
const noop = () => {
|
||||
|
16
src/html/_preload_roboto.html.template
Normal file
16
src/html/_preload_roboto.html.template
Normal file
@ -0,0 +1,16 @@
|
||||
<script>
|
||||
if (navigator.userAgent.indexOf("Android") === -1 &&
|
||||
navigator.userAgent.indexOf("CrOS") === -1) {
|
||||
function _pf(src, type) {
|
||||
const el = document.createElement("link");
|
||||
el.rel = "preload";
|
||||
el.as = "font";
|
||||
el.type = "font/woff2";
|
||||
el.href = src;
|
||||
el.crossOrigin = "anonymous";
|
||||
document.head.append(el);
|
||||
}
|
||||
_pf("/static/fonts/roboto/Roboto-Regular.woff2");
|
||||
_pf("/static/fonts/roboto/Roboto-Medium.woff2");
|
||||
}
|
||||
</script>
|
@ -3,18 +3,6 @@
|
||||
<head>
|
||||
<title>Home Assistant</title>
|
||||
<link rel="preload" href="<%= latestPageJS %>" as="script" crossorigin="use-credentials" />
|
||||
<link
|
||||
rel="preload"
|
||||
href="/static/fonts/roboto/Roboto-Light.woff2"
|
||||
as="font"
|
||||
crossorigin
|
||||
/>
|
||||
<link
|
||||
rel="preload"
|
||||
href="/static/fonts/roboto/Roboto-Regular.woff2"
|
||||
as="font"
|
||||
crossorigin
|
||||
/>
|
||||
<%= renderTemplate('_header') %>
|
||||
<style>
|
||||
.content {
|
||||
@ -46,6 +34,7 @@
|
||||
</div>
|
||||
|
||||
<%= renderTemplate('_js_base') %>
|
||||
<%= renderTemplate('_preload_roboto') %>
|
||||
|
||||
<script type="module" crossorigin="use-credentials">
|
||||
import "<%= latestPageJS %>";
|
||||
|
@ -2,18 +2,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="preload" href="<%= latestCoreJS %>" as="script" crossorigin="use-credentials" />
|
||||
<link
|
||||
rel="preload"
|
||||
href="/static/fonts/roboto/Roboto-Regular.woff2"
|
||||
as="font"
|
||||
crossorigin
|
||||
/>
|
||||
<link
|
||||
rel="preload"
|
||||
href="/static/fonts/roboto/Roboto-Medium.woff2"
|
||||
as="font"
|
||||
crossorigin
|
||||
/>
|
||||
<link rel="preload" href="<%= latestAppJS %>" as="script" crossorigin="use-credentials" />
|
||||
<%= renderTemplate('_header') %>
|
||||
<title>Home Assistant</title>
|
||||
<link
|
||||
@ -61,10 +50,11 @@
|
||||
<home-assistant> </home-assistant>
|
||||
|
||||
<%= renderTemplate('_js_base') %>
|
||||
<%= renderTemplate('_preload_roboto') %>
|
||||
|
||||
<script type="module" crossorigin="use-credentials">
|
||||
import "<%= latestCoreJS %>";
|
||||
import "<%= latestAppJS %>";
|
||||
import("<%= latestCoreJS %>");
|
||||
import("<%= latestAppJS %>");
|
||||
window.customPanelJS = "<%= latestCustomPanelJS %>";
|
||||
</script>
|
||||
{% for extra_module in extra_modules -%}
|
||||
@ -81,6 +71,8 @@
|
||||
|
||||
<% if (useRollup) { %>
|
||||
_ls("/static/js/s.min.js").onload = function() {
|
||||
// Although core and app can load in any order, we need to
|
||||
// force loading core first because it contains polyfills
|
||||
return System.import("<%= es5CoreJS %>").then(function() {
|
||||
System.import("<%= es5AppJS %>");
|
||||
});
|
||||
|
@ -3,18 +3,6 @@
|
||||
<head>
|
||||
<title>Home Assistant</title>
|
||||
<link rel="preload" href="<%= latestPageJS %>" as="script" crossorigin="use-credentials" />
|
||||
<link
|
||||
rel="preload"
|
||||
href="/static/fonts/roboto/Roboto-Light.woff2"
|
||||
as="font"
|
||||
crossorigin
|
||||
/>
|
||||
<link
|
||||
rel="preload"
|
||||
href="/static/fonts/roboto/Roboto-Regular.woff2"
|
||||
as="font"
|
||||
crossorigin
|
||||
/>
|
||||
<%= renderTemplate('_header') %>
|
||||
<style>
|
||||
.content {
|
||||
@ -48,6 +36,7 @@
|
||||
</div>
|
||||
|
||||
<%= renderTemplate('_js_base') %>
|
||||
<%= renderTemplate('_preload_roboto') %>
|
||||
|
||||
<script type="module" crossorigin="use-credentials">
|
||||
import "<%= latestPageJS %>";
|
||||
|
@ -93,7 +93,18 @@ export class HomeAssistantAppEl extends HassElement {
|
||||
|
||||
protected async _initialize() {
|
||||
try {
|
||||
const { auth, conn } = await window.hassConnection;
|
||||
let result;
|
||||
|
||||
if (window.hassConnection) {
|
||||
result = await window.hassConnection;
|
||||
} else {
|
||||
// In the edge case that
|
||||
result = await new Promise((resolve) => {
|
||||
window.hassConnectionReady = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
const { auth, conn } = result;
|
||||
this._haVersion = conn.haVersion;
|
||||
this.initializeHass(auth, conn);
|
||||
} catch (err) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user