You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

12 KiB

1NoCategoryGuidelineDescriptionDoDon'tCode GoodCode BadSeverityDocs URL
21ArchitectureUse Islands ArchitectureAstro's partial hydration only loads JS for interactive componentsInteractive components with client directivesHydrate entire page like traditional SPA<Counter client:load />Everything as client componentHighhttps://docs.astro.build/en/concepts/islands/
32ArchitectureDefault to zero JSAstro ships zero JS by default - add only when neededStatic components without client directiveAdd client:load to everything<Header /> (static)<Header client:load /> (unnecessary)Highhttps://docs.astro.build/en/basics/astro-components/
43ArchitectureChoose right client directiveDifferent directives for different hydration timingclient:visible for below-fold client:idle for non-criticalclient:load for everything<Comments client:visible /><Comments client:load />Mediumhttps://docs.astro.build/en/reference/directives-reference/#client-directives
54ArchitectureUse content collectionsType-safe content management for blogs docsContent collections for structured contentLoose markdown files without schemaconst posts = await getCollection('blog')import.meta.glob('./posts/*.md')Highhttps://docs.astro.build/en/guides/content-collections/
65ArchitectureDefine collection schemasZod schemas for content validationSchema with required fields and typesNo schema validationdefineCollection({ schema: z.object({...}) })defineCollection({})Highhttps://docs.astro.build/en/guides/content-collections/#defining-a-collection-schema
76RoutingUse file-based routingCreate routes by adding .astro files in pages/pages/ directory for routesManual route configurationsrc/pages/about.astroCustom router setupMediumhttps://docs.astro.build/en/basics/astro-pages/
87RoutingDynamic routes with bracketsUse [param] for dynamic routesBracket notation for paramsQuery strings for dynamic contentpages/blog/[slug].astropages/blog.astro?slug=xMediumhttps://docs.astro.build/en/guides/routing/#dynamic-routes
98RoutingUse getStaticPaths for SSGGenerate static pages at build timegetStaticPaths for known dynamic routesFetch at runtime for static contentexport async function getStaticPaths() { return [...] }No getStaticPaths with dynamic routeHighhttps://docs.astro.build/en/reference/api-reference/#getstaticpaths
109RoutingEnable SSR when neededServer-side rendering for dynamic contentoutput: 'server' or 'hybrid' for dynamicSSR for purely static sitesexport const prerender = false;SSR for static blogMediumhttps://docs.astro.build/en/guides/server-side-rendering/
1110ComponentsKeep .astro for staticUse .astro components for static contentAstro components for layout structureReact/Vue for static markup<Layout><slot /></Layout><ReactLayout>{children}</ReactLayout>High
1211ComponentsUse framework components for interactivityReact Vue Svelte for complex interactivityFramework component with client directiveAstro component with inline scripts<ReactCounter client:load /><script> in .astro for complex stateMediumhttps://docs.astro.build/en/guides/framework-components/
1312ComponentsPass data via propsAstro components receive props in frontmatterAstro.props for component dataGlobal state for simple dataconst { title } = Astro.props;Import global storeLowhttps://docs.astro.build/en/basics/astro-components/#component-props
1414ComponentsColocate component stylesScoped styles in component file<style> in same .astro fileSeparate CSS files for component styles<style> .card { } </style>import './Card.css'Low
1515StylingUse scoped styles by defaultAstro scopes styles to component automatically<style> for component-specific stylesGlobal styles for everything<style> h1 { } </style> (scoped)<style is:global> for everythingMediumhttps://docs.astro.build/en/guides/styling/#scoped-styles
1616StylingUse is:global sparinglyGlobal styles only when truly neededis:global for base styles or overridesis:global for component styles<style is:global> body { } </style><style is:global> .card { } </style>Medium
1717StylingIntegrate Tailwind properlyUse @astrojs/tailwind integrationOfficial Tailwind integrationManual Tailwind setupnpx astro add tailwindManual PostCSS configLowhttps://docs.astro.build/en/guides/integrations-guide/tailwind/
1818StylingUse CSS variables for themingDefine tokens in :rootCSS custom properties for themesHardcoded colors everywhere:root { --primary: #3b82f6; }color: #3b82f6; everywhereMedium
1919DataFetch in frontmatterData fetching in component frontmatterTop-level await in frontmatteruseEffect for initial dataconst data = await fetch(url)client-side fetch on mountHighhttps://docs.astro.build/en/guides/data-fetching/
2020DataUse Astro.glob for local filesImport multiple local filesAstro.glob for markdown/data filesManual imports for each fileconst posts = await Astro.glob('./posts/*.md')import post1; import post2;Medium
2121DataPrefer content collections over globType-safe collections for structured contentgetCollection() for blog/docsAstro.glob for structured contentawait getCollection('blog')await Astro.glob('./blog/*.md')High
2222DataUse environment variables correctlyImport.meta.env for env varsPUBLIC_ prefix for client varsExpose secrets to clientimport.meta.env.PUBLIC_API_URLimport.meta.env.SECRET in clientHighhttps://docs.astro.build/en/guides/environment-variables/
2323PerformancePreload critical assetsUse link preload for important resourcesPreload fonts above-fold imagesNo preload hints<link rel="preload" href="font.woff2" as="font">No preload for critical assetsMedium
2424PerformanceOptimize images with astro:assetsBuilt-in image optimization<Image /> component for optimization<img> for local imagesimport { Image } from 'astro:assets';<img src="./image.jpg">Highhttps://docs.astro.build/en/guides/images/
2525PerformanceUse picture for responsive imagesMultiple formats and sizes<Picture /> for art directionSingle image size for all screens<Picture /> with multiple sources<Image /> with single sizeMedium
2626PerformanceLazy load below-fold contentDefer loading non-critical contentloading=lazy for images client:visible for componentsLoad everything immediately<img loading="lazy">No lazy loadingMedium
2727PerformanceMinimize client directivesEach directive adds JS bundleAudit client: usage regularlySprinkle client:load everywhereOnly interactive components hydratedEvery component with client:loadHigh
2828ViewTransitionsEnable View TransitionsSmooth page transitions<ViewTransitions /> in headFull page reloadsimport { ViewTransitions } from 'astro:transitions';No transition APIMediumhttps://docs.astro.build/en/guides/view-transitions/
2929ViewTransitionsUse transition:nameNamed elements for morphingtransition:name for persistent elementsUnnamed transitions<header transition:name="header"><header> without nameLow
3030ViewTransitionsHandle transition:persistKeep state across navigationstransition:persist for media playersRe-initialize on every navigation<video transition:persist id="player">Video restarts on navigationMedium
3131ViewTransitionsAdd fallback for no-JSGraceful degradationContent works without JSRequire JS for basic navigationStatic content accessibleBroken without ViewTransitions JSHigh
3232SEOUse built-in SEO componentHead management for meta tagsAstro SEO integration or manual headNo meta tags<title>{title}</title><meta name="description">No SEO tagsHigh
3333SEOGenerate sitemapAutomatic sitemap generation@astrojs/sitemap integrationManual sitemap maintenancenpx astro add sitemapHand-written sitemap.xmlMediumhttps://docs.astro.build/en/guides/integrations-guide/sitemap/
3434SEOAdd RSS feed for contentRSS for blogs and content sites@astrojs/rss for feed generationNo RSS feedrss() helper in pages/rss.xml.jsNo feed for blogLowhttps://docs.astro.build/en/guides/rss/
3536IntegrationsUse official integrationsAstro's integration systemnpx astro add for integrationsManual configurationnpx astro add reactManual React setupMediumhttps://docs.astro.build/en/guides/integrations-guide/
3637IntegrationsConfigure integrations in astro.configCentralized configurationintegrations array in configScattered configurationintegrations: [react(), tailwind()]Multiple config filesLow
3738IntegrationsUse adapter for deploymentPlatform-specific adaptersCorrect adapter for hostWrong or no adapter@astrojs/vercel for VercelNo adapter for SSRHighhttps://docs.astro.build/en/guides/deploy/
3839TypeScriptEnable TypeScriptType safety for Astro projectstsconfig.json with astro typesNo TypeScriptAstro TypeScript templateJavaScript onlyMediumhttps://docs.astro.build/en/guides/typescript/
3940TypeScriptType component propsDefine prop interfacesProps interface in frontmatterUntyped propsinterface Props { title: string }No props typingMedium
4041TypeScriptUse strict modeCatch errors earlystrict: true in tsconfigLoose TypeScript configstrictest templatebase templateLow
4142MarkdownUse MDX for componentsComponents in markdown content@astrojs/mdx for interactive docsPlain markdown with workarounds<Component /> in .mdxHTML in .md filesMediumhttps://docs.astro.build/en/guides/integrations-guide/mdx/
4243MarkdownConfigure markdown pluginsExtend markdown capabilitiesremarkPlugins rehypePlugins in configManual HTML for featuresremarkPlugins: [remarkToc]Manual TOC in every postLow
4344MarkdownUse frontmatter for metadataStructured post metadataFrontmatter with typed schemaInline metadatatitle date in frontmatter# Title as first lineMedium
4445APIUse API routes for endpointsServer endpoints in pages/apipages/api/[endpoint].ts for APIsExternal API for simple endpointspages/api/posts.json.tsSeparate Express serverMediumhttps://docs.astro.build/en/guides/endpoints/
4546APIReturn proper responsesUse Response objectnew Response() with headersPlain objectsreturn new Response(JSON.stringify(data))return dataMedium
4647APIHandle methods correctlyExport named method handlersexport GET POST handlersSingle default exportexport const GET = async () => {}export default async () => {}Low
4748SecuritySanitize user contentPrevent XSS in dynamic contentset:html only for trusted contentset:html with user input<Fragment set:html={sanitized} /><div set:html={userInput} />High
4849SecurityUse HTTPS in productionSecure connectionsHTTPS for all production sitesHTTP in productionhttps://example.comhttp://example.comHigh
4950SecurityValidate API inputCheck and sanitize all inputZod validation for API routesTrust all inputconst body = schema.parse(data)const body = await request.json()High
5051BuildUse hybrid renderingMix static and dynamic pagesoutput: 'hybrid' for flexibilityAll SSR or all staticprerender per-page basisSingle rendering modeMediumhttps://docs.astro.build/en/guides/server-side-rendering/#hybrid-rendering
5152BuildAnalyze bundle sizeMonitor JS bundle impactBuild output shows bundle sizesIgnore bundle growthCheck astro build outputNo size monitoringMedium
5253BuildUse prefetchPreload linked pagesprefetch integrationNo prefetch for navigationnpx astro add prefetchManual prefetchLowhttps://docs.astro.build/en/guides/prefetch/