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
Read translation (VI): Kiến trúc Static-First với Astro và 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
- Use
astro:i18n(getRelativeLocaleUrl) for localized page routes. - Wrap files served from
public/(such as the sample CV PDF or Pagefind bundle) withgetAssetUrl(...). - Store article images inside
src/assets/soastro:assetsgenerates 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.