Vuong
VIEN
Back to blog
Published: Updated: 2 min read

Static-First Architecture with Astro and Tailwind CSS v4

Designing a fast personal portfolio and blog with subpath-safe GitHub Pages routing and resilient bilingual support.

  • #astro
  • #architecture
  • #tailwindcss
Diagram illustrating Static-First architecture with Astro and Tailwind CSS v4
Table of contents

Why Static-First Matters

For a personal portfolio and technical blog, content changes when you publish rather than on every incoming request. A static-first workflow brings concrete advantages:

  • Predictable performance and caching on static hosting such as GitHub Pages.
  • Minimal client-side JavaScript, loading interactive widgets only on demand.
  • Deterministic HTML output that is straightforward to audit for SEO and accessibility.

Keeping Every Asset Base-Aware

Hardcoding root-relative links such as /images/cover.png breaks whenever a site is hosted under a repository subpath like /Personal-Website/. Wrapping internal asset paths in a base-aware helper keeps both root and subpath deployments consistent:

export function withBase(path: string, base: string = import.meta.env.BASE_URL): string {
  if (/^(?:[a-z][a-z0-9+.-]*:|\/\/|#)/i.test(path)) {
    return path;
  }
  const normalizedBase = !base || base === '/' ? '' : base.replace(/\/+$/, '');
  const normalizedPath = path.startsWith('/') ? path : `/${path}`;
  if (normalizedBase && (normalizedPath === normalizedBase || normalizedPath.startsWith(`${normalizedBase}/`))) {
    return normalizedPath;
  }
  return `${normalizedBase}${normalizedPath}`;
}

Practical Guidelines

  1. Use astro:i18n (getRelativeLocaleUrl) for localized page routes.
  2. Wrap files served from public/ (such as the sample CV PDF or Pagefind bundle) with getAssetUrl(...).
  3. Store article images inside src/assets/ so astro:assets generates responsive WebP/AVIF assets with explicit dimensions.

Lazy Search and Draft Isolation

Static Search with Pagefind

Instead of shipping a monolithic JSON payload on initial load, Pagefind lazily fetches chunked search indices only when the reader interacts with the search input.

Strict Draft Exclusion

Entries marked with draft: true are filtered out in production (import.meta.env.PROD) across page routes, rss.xml, sitemap-*.xml, and the generated Pagefind index.

Back to blog