JAlcocerTech E-books

Shipping Sites That Score Well

A lead engine is only as good as the sites feeding it. I run a free website audit tool (performance, SEO, security and a link crawl, combined into one score), so I eventually ran it against my own sites, with every check on.

The main site scored 71.

SiteBeforeAfter
Main site7199
Ebooks library95100
Consulting page8497

None of the fixes was big. Here they are, in the order I’d apply them to any new site.

1. Fix the measuring tool first

Two “problems” were bugs in my own tool: it only looked for /sitemap.xml (Astro writes /sitemap-index.xml), and it searched only the first 5 KB of HTML for contact details. When your own tool disagrees with what you can see in a browser, check the tool before changing the site.

2. Have a real 404 page

On Cloudflare Pages, a static site without 404.html answers every unknown URL with the homepage and status 200. Link checkers then see nothing broken, and search engines see copies of your homepage everywhere. Adding one 404 page revealed 273 broken links in the ebooks: chapters linked to each other as other-chapter.md (fine on GitHub, broken on the web). A small remark plugin now rewrites those links at build time.

3. Sitemap, robots.txt, canonical

  • @astrojs/sitemap with site set in the config.
  • robots.txt with a Sitemap: line pointing to it.
  • <link rel="canonical"> on every page, built from the path only (no query string), and og:url set to the same value.
  • One canonical host per site: apex or www, and the *.pages.dev address redirected too.

4. Security headers, tested in a browser

All in public/_headers:

/*
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  X-Frame-Options: DENY
  X-Content-Type-Options: nosniff
  Referrer-Policy: strict-origin-when-cross-origin
  Permissions-Policy: camera=(), microphone=(), geolocation=()
  Content-Security-Policy: default-src 'self'; object-src 'none'; frame-ancestors 'none'; form-action 'self'; …

The CSP allowlist comes from the built site: grep dist/ for every external origin, not memory. A demo that needs 'unsafe-eval' gets its own rule, and the ! prefix removes the general header first (two CSP headers means both are enforced). Then a Playwright script visits one page of each type and collects console messages containing “Refused”. Zero violations, and features checked: diagrams render, the booking iframe appears.

5. Self-host your fonts

Mobile LCP was 3.8 s, and Lighthouse’s breakdown showed almost all of it was render delay: the browser waiting on render-blocking Google Fonts CSS, which the template loaded twice. Installing the fonts from npm (Fontsource) puts them in the site’s own CSS bundle. LCP dropped to 2.4 s, and visitors’ browsers stopped contacting Google on every page.

6. Load heavy embeds on approach

The booking calendar at the bottom of the consulting page loaded about 1 MB of JavaScript for every visitor. Wrapping the vendor’s snippet in an IntersectionObserver (start when the calendar is 800 px away) took it off the first load. Playwright confirmed: zero requests to the booking service before scrolling.

7. Real share images

Two sites shared a 248×56 logo as their og:image; the third a 675 KB square JPEG named .png. A tag check passes all three. Now:

  • 1200×630, JPEG or PNG, under 300 KB. Not WebP: LinkedIn skips WebP share images.
  • Rendered from HTML with Playwright, using each site’s own fonts, so a copy change is one command.
  • One default card per site; articles and books can bring their own, and fall back to the default.

8. Scheduled posts on a static site

Static sites decide what’s published when they’re built, and Pages builds when you push. So a post dated Tuesday waits for the next push after Tuesday. The fix is a cron Worker that calls each site’s deploy hook once a day, just after midnight in the readers’ timezone.

Two traps:

  • Astro doesn’t hide future posts. Hugo does by default; with Astro, filter both the list and getStaticPaths.
  • Compare dates in the readers’ timezone. A frontmatter date is midnight UTC; at 23:30 UTC it’s already tomorrow in Poland but not in UTC.
export function isPublished(entry: { data: { date?: Date } }, now = new Date()) {
  if (!entry.data.date) return true;
  const today = new Intl.DateTimeFormat("en-CA", { timeZone: "Europe/Warsaw" }).format(now);
  return entry.data.date.toISOString().slice(0, 10) <= today;
}

Cloudflare’s email obfuscation injects a render-blocking script on every page that shows an address. The footer now links to a contact form; the address stays where it’s needed: privacy notice, terms, the contact page, and the site that sells a paid service.

10. Deploy only what you committed

For direct-upload sites, build from a git worktree of the commit with npm ci, never from your working folder. It also proves the lockfile is complete. And make sure --branch matches the project’s production branch: anything else silently becomes a preview deployment.

Next: pragmatism, with an exit.