--- // 1. Configuration import pkg from '../../../package.json'; const CDN_BASE = `https://cdn.jsdelivr.net/npm/htmx.org@${pkg.version}/dist`; const EXTENSION_LIST = [ {name: 'websockets', comingSoon: true}, {name: 'webrtc', comingSoon: true}, ]; // 2. Utility: Fetch file size (Server Side) async function getFileSize(url: string) { try { const res = await fetch(url, {method: 'HEAD'}); const bytes = parseInt(res.headers.get('content-length') || '0', 10); return bytes ? parseFloat((bytes / 1024).toFixed(1)) : 0; } catch (e) { return 0; } } // 3. Execution: Parallel Fetching const [coreMin, coreFull] = await Promise.all([ getFileSize(`${CDN_BASE}/htmx.min.js`), getFileSize(`${CDN_BASE}/htmx.js`) ]); const extensions = await Promise.all(EXTENSION_LIST.map(async (ext) => { // Skip fetching for "Coming Soon" items if (ext.comingSoon) return {...ext, size: 0, full: 0}; return { ...ext, size: await getFileSize(`${CDN_BASE}/ext/${ext.name}.min.js`), full: await getFileSize(`${CDN_BASE}/ext/${ext.name}.js`) }; })); ---
-- Build core script tag render #script-tag with (url: :base + '/htmx' + extStr + '.js') set html to it -- Add extension script tags repeat for e in exts if min increment total by (e.dataset.min as Number) else increment total by (e.dataset.full as Number) end render #script-tag with (url: :base + '/ext/' + e.value + extStr + '.js') set html to html + '\n' + it end -- Render output put html into #code put total.toFixed(1) into #total -- Update dropdown label if exts.length > 0 put exts.length + ' added' into #count-lbl add .text-neutral-900 .dark:text-white to #count-lbl else put 'add extensions' into #count-lbl remove .text-neutral-900 .dark:text-white from #count-lbl end `}>
{[0, 0, 0].map(() =>
)}
~0 KB