← back to Ga Allsites
Inject boot data server-side for instant first paint + credentialed-URL resilience
e780b00d4725942dd3c6f767db5dfd15a7221c8d · 2026-08-04 13:42:57 -0700 · Steve Abrams
Files touched
A dashboard-preview.pngM server.py
Diff
commit e780b00d4725942dd3c6f767db5dfd15a7221c8d
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Tue Aug 4 13:42:57 2026 -0700
Inject boot data server-side for instant first paint + credentialed-URL resilience
---
dashboard-preview.png | Bin 0 -> 111700 bytes
server.py | 12 ++++++++----
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/dashboard-preview.png b/dashboard-preview.png
new file mode 100644
index 0000000..7a0436e
Binary files /dev/null and b/dashboard-preview.png differ
diff --git a/server.py b/server.py
index fa51858..426e606 100644
--- a/server.py
+++ b/server.py
@@ -91,6 +91,7 @@ PAGE = r"""<!DOCTYPE html><html><head><meta charset="utf-8">
<tbody id="tb"></tbody>
<tfoot><tr id="tf"></tr></tfoot>
</table></div>
+<script>window.__BOOT__=/*BOOTDATA*/null/*/BOOTDATA*/;</script>
<script>
const COLS=[
{k:'property',l:'Site',t:'l',fmt:(r)=>`<a href="https://analytics.google.com/analytics/web/#/p${r.property_id}/reports/intelligenthome" target="_blank" rel="noopener noreferrer">${esc(r.property||'?')}</a>${r.error?` <span class="err" title="${esc(r.error)}">⚠</span>`:''}`},
@@ -146,7 +147,8 @@ function render(){
function fmtAge(iso){const s=(Date.now()-new Date(iso))/1000;
if(s<90)return 'just now';if(s<3600)return Math.round(s/60)+'m ago';return Math.round(s/3600)+'h ago';}
async function load(){
- const r=await fetch('/api/data');DATA=await r.json();
+ if(window.__BOOT__){DATA=window.__BOOT__;window.__BOOT__=null;}
+ else{const r=await fetch(location.origin+'/api/data');DATA=await r.json();}
const active=DATA.rows.filter(x=>dig(x,'d30.sessions')>0).length;
const t7=DATA.rows.reduce((s,x)=>s+dig(x,'d7.sessions'),0);
const t30=DATA.rows.reduce((s,x)=>s+dig(x,'d30.sessions'),0);
@@ -164,8 +166,8 @@ document.getElementById('dens').oninput=e=>{document.documentElement.style.setPr
if(localStorage.gaDens){document.getElementById('dens').value=localStorage.gaDens;document.getElementById('dens').oninput({target:{value:localStorage.gaDens}});}
document.getElementById('refresh').onclick=async()=>{
const m=document.getElementById('rmsg');m.textContent='refreshing… (~70s, pulls all sites)';
- await fetch('/api/refresh',{method:'POST'});
- let tries=0;const iv=setInterval(async()=>{tries++;const r=await fetch('/api/status');const j=await r.json();
+ await fetch(location.origin+'/api/refresh',{method:'POST'});
+ let tries=0;const iv=setInterval(async()=>{tries++;const r=await fetch(location.origin+'/api/status');const j=await r.json();
if(!j.refreshing){clearInterval(iv);m.textContent='updated ✓';load();setTimeout(()=>m.textContent='',3000);}
else m.textContent=`refreshing… ${tries*3}s`;},3000);
};
@@ -195,7 +197,9 @@ class H(BaseHTTPRequestHandler):
if not self._auth():
return
if self.path == "/" or self.path.startswith("/index"):
- self._send(200, "text/html", PAGE.encode())
+ boot = CACHE.read_text() if CACHE.exists() else "null"
+ html = PAGE.replace("/*BOOTDATA*/null/*/BOOTDATA*/", boot)
+ self._send(200, "text/html", html.encode())
elif self.path == "/api/data":
body = CACHE.read_bytes() if CACHE.exists() else b'{"rows":[],"property_count":0,"generated_at":"1970-01-01T00:00:00","elapsed_s":0}'
self._send(200, "application/json", body)
← a646572 GA all-sites dashboard: cache-ETL + live local server (DTD O
·
back to Ga Allsites
·
Add launchd ETL scheduler (30min auto-refresh); use homebrew fa60089 →