Ask Before You Compare: A Tariff Widget That Waits Its Turn
Photo: smartphone showing energy bill comparison on kitchen table UK, via as1.ftcdn.net
The form earns the money. The widget just looks clever.
A three-person energy broker we know had a good autumn: organic traffic up, quote requests up. Then marketing added a partner's live tariff comparison embed to the landing page. Page weight went from roughly 180 KB to a shade over 600 KB. On a mid-range Android phone over 4G, time to interactive went from about 2.4 seconds to something north of seven. On a rural connection in Cornwall, the postcode field took a noticeable beat to accept the first keystroke.
The quote form is the lead. Everything else on that page is decoration around it. So the fix wasn't to drop the comparison widget — it was to make it wait until somebody actually wants it.
What the widget needs, and what it doesn't
Strip the embed back and it needs three things: a network connection, a DOM node to mount into, and a human who wants a tariff comparison. The first two are available at page load. The third doesn't exist until someone clicks something.
That's the whole design. Everything below follows from it.
Two states, one page
State one: static. The form, a short table of representative tariffs, and a button. The table is plain HTML — six rows, no script, about 6 KB. It carries a date stamp: checked against the Ofgem price cap that took effect on 1 October 2026. That matters, because the cap moves four times a year (1 January, 1 April, 1 July, 1 October) and a table with a visible date is honest in a way that a live widget isn't necessarily.
State two: live. Nothing loads until intent shows up. Intent means a click on Compare live tariffs, or focus landing on that button for keyboard users, where you can start the TLS handshake a fraction early.
The loader
const PARTNER = 'https://partner.example/embed.js';
let state = 'idle';
export async function loadWidget(slot) {
if (state === 'loading' || state === 'ready') return;
state = 'loading';
slot.dataset.state = 'loading';
try {
await withTimeout(inject(PARTNER), 6000);
state = 'ready';
slot.dataset.state = 'ready';
} catch {
state = 'failed';
slot.dataset.state = 'fallback';
slot.querySelector('[data-fallback]').hidden = false;
}
}
function inject(src) {
return new Promise((resolve, reject) => {
const s = document.createElement('script');
s.src = src;
s.async = true;
s.onload = resolve;
s.onerror = () => reject(new Error('blocked'));
document.head.append(s);
});
}
function withTimeout(promise, ms) {
return Promise.race([
promise,
new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), ms))
]);
}
Attach the promise rejection with care — a rejected inject losing its handler will show up in your error monitoring as noise you'll spend an afternoon chasing. Give the timeout a tidy message and move on.
One more trick worth the four lines: on pointerenter of the button, inject a <link rel='preconnect'> for the partner origin. It shaves a few hundred milliseconds off the first real request. It also leaks the visitor's IP to a third party, so only do it after they've shown intent or consented — more on that below.
Consent isn't a detail you can skip
A tariff comparison embed is not a strictly necessary service. It drops cookies, it shares a postcode with a third party, and under PECR and the ICO's guidance that means consent before it runs — not a banner you hope nobody reads, but an actual recorded choice or an explicit click on a button that says what it does.
So label the button honestly: Load live comparison (loads partner script). Nobody has ever bounced because a button was honest. Plenty of people bounce because a page they didn't ask for a quote from became slow.
There's a second UK-specific wrinkle: partner embeds love to call home on mount with a full address. Make sure your own privacy notice says who, and make sure the widget only receives what your form actually needs — a postcode district is plenty for a comparison.
Keep the form out of the blast radius
- Submit to your own endpoint. The lead is your asset. The widget is a nice-to-have and should never sit between the form and its handler.
- Reserve the slot height. A fixed
min-heighton the mount point stops the layout shifting when the embed finally paints. - Scope the styles. Partner embeds ship
!importantrules attached to global selectors. Mount them inside a container and check your input borders afterwards. - Never await it in the submit handler. If the widget is dying, the form still posts.
Measure the boring things
Three numbers tell you whether this is working: INP on the postcode field before and after the change; widget load success rate broken down by connection type; and clicks from the static table through to the form. That last one is the honest one. If the static table converts nearly as well as the live widget, you've learned something useful about how much the embed is really worth.
The fallback table is not a consolation prize
Most visitors will read the table and never touch the widget. Treat it accordingly: keep the cap date current, keep the regional distribution-area notes accurate, and don't let it rot because the live version is flashier.
Thirty lines of JavaScript, a button, and a table. The meter stops running until somebody asks it to.