Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/(app)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export default async function AppLayout({ children }: { children: React.ReactNod
src="/logo.svg"
alt="CrawlProof"
className="h-16 w-auto"
width={320}
width={181}
height={64}
style={{ height: 64, width: "auto" }}
/>
</Link>
<nav className="flex flex-wrap items-center gap-x-4 gap-y-2 text-sm text-[var(--color-muted)]">
Expand Down
48 changes: 46 additions & 2 deletions app/ad.js/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,49 @@ ${VISITOR_SNIPPET}
return 'auto';
}
}
// --- placeholder --------------------------------------------------------
// Between the tag running and the creative arriving the slot used to be an
// empty, zero-height box, so the page jumped when the ad landed, and on a
// slow host stylesheet whatever raw markup sat there read like an injected
// ad. Instead we paint a skeleton straight away: an inline SVG built here
// (no request, nothing to wait for), sized to the format so the space is
// reserved, faint enough to read as "loading" rather than as content.
function skeleton(w, h, dark) {
var ink = dark ? '#ffffff' : '#000000';
var r = function (x, y, rw, rh, op) {
return "<rect x='" + Math.round(x) + "' y='" + Math.round(y) + "' width='" + Math.max(0, Math.round(rw))
+ "' height='" + Math.max(0, Math.round(rh)) + "' rx='3' fill='" + ink + "' fill-opacity='" + op + "'/>";
};
var b = r(0, 0, w, h, 0.04);
if (h >= 120) {
var ih = h * 0.55;
b += r(12, 12, w - 24, ih, 0.06) + r(12, ih + 26, (w - 24) * 0.72, 10, 0.07) + r(12, ih + 44, (w - 24) * 0.45, 10, 0.05);
} else if (h >= 50) {
var s = h - 16;
b += r(8, 8, s, s, 0.06) + r(s + 18, h / 2 - 12, (w - s - 26) * 0.7, 8, 0.07) + r(s + 18, h / 2 + 4, (w - s - 26) * 0.45, 8, 0.05);
} else {
b += r(8, h / 2 - 5, w * 0.5, 10, 0.07);
}
return "<svg xmlns='http://www.w3.org/2000/svg' width='" + w + "' height='" + h + "' viewBox='0 0 " + w + " " + h + "'>" + b + "</svg>";
}
function showPlaceholder(el, format, theme) {
// The publisher's own fallback markup is theirs to show; leave it alone.
if (el.children.length) return;
var dims = SIZES[format] || SIZES.banner_300x250;
var dark = theme === 'dark' || (theme !== 'light' && window.matchMedia && matchMedia('(prefers-color-scheme: dark)').matches);
var ph = document.createElement('div');
ph.setAttribute('data-cp-placeholder', '');
ph.setAttribute('aria-hidden', 'true');
var url = 'data:image/svg+xml,' + encodeURIComponent(skeleton(dims[0], dims[1], dark));
ph.style.cssText = 'display:block;max-width:100%;overflow:hidden;border-radius:4px;'
+ 'width:' + (format === 'text_link' ? '100%' : dims[0] + 'px') + ';height:' + dims[1] + 'px;'
+ 'background:url("' + url + '") left top no-repeat';
el.appendChild(ph);
}
function clearPlaceholder(el) {
var ph = el.querySelector('[data-cp-placeholder]');
if (ph && ph.parentNode === el) el.removeChild(ph);
}
function fill(el) {
if (el.getAttribute('data-cp-filled')) return;
var slot = el.getAttribute('data-slot');
Expand All @@ -87,10 +130,11 @@ ${VISITOR_SNIPPET}
var theme = detectTheme(el);
if (theme === 'light' || theme === 'dark') q += '&theme=' + theme;
el.setAttribute('data-cp-filled', '1');
showPlaceholder(el, format, theme);
fetch(ORIGIN + '/api/ads/serve' + q, { mode: 'cors', credentials: 'omit', cache: 'no-store' })
.then(function(r){ return r.json(); })
.then(function(res){
if (!res || !res.ok || !res.html) { el.removeAttribute('data-cp-filled'); return; }
if (!res || !res.ok || !res.html) { clearPlaceholder(el); el.removeAttribute('data-cp-filled'); return; }
// Serving may downgrade a format that could not fit the measured
// width, so size from what came back rather than what we asked for.
if (res.format && SIZES[res.format]) format = res.format;
Expand Down Expand Up @@ -148,7 +192,7 @@ ${VISITOR_SNIPPET}
}
el.appendChild(iframe);
})
.catch(function(){ el.removeAttribute('data-cp-filled'); });
.catch(function(){ clearPlaceholder(el); el.removeAttribute('data-cp-filled'); });
}
function scan() {
var nodes = document.querySelectorAll('[data-cp-ad]');
Expand Down
12 changes: 11 additions & 1 deletion components/site-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ export async function SiteHeader() {
<div className="mx-auto flex max-w-6xl items-center justify-between gap-3 px-4 py-3 sm:px-6">
<Link href="/" className="flex shrink-0 items-center" aria-label="CrawlProof home">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src="/logo.svg" alt="CrawlProof" className="h-16 w-auto" />
{/* width/height + inline height keep the logo 64px tall before the
stylesheet lands; without them a slow CSS load paints the SVG at
full viewport width. */}
<img
src="/logo.svg"
alt="CrawlProof"
className="h-16 w-auto"
width={181}
height={64}
style={{ height: 64, width: "auto" }}
/>
</Link>
<nav className="flex flex-wrap items-center gap-x-4 gap-y-2 text-sm text-[var(--color-muted)]">
<Link
Expand Down
Loading