mcpField
P
perf-astro

perf-astro

github.com/tech-leads-club開発7.1k284 回インストール3 日前に更新
リポジトリ

perf-astro について

Astroサイトのパフォーマンス最適化を扱うガイドです。ビルド成果物やページ読み込みを改善したい開発者向けに、クリティカルCSSのインライン化、圧縮、レイアウト、Lighthouse測定を説明します。

主な機能

  1. 01クリティカルCSSの抽出とインライン化
  2. 02HTML、CSS、JavaScriptの圧縮
  3. 03Astroのレイアウト指針
  4. 04Lighthouseによるパフォーマンス測定

活用シーン

  1. 01Astroページのレンダリングを妨げるCSSの削減
  2. 02本番ビルドでのアセット圧縮
  3. 03Lighthouseによるモバイル性能の測定

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/tech-leads-club/agent-skills --skill perf-astro

インストール後、Claude Code で/perf-astroを入力して読み込まれたか確認します。

詳細

Astro のパフォーマンス向上ガイド

Lighthouse スコア 95 以上を実現する、Astro に特化した最適化です。

クイックセットアップ

npm install astro-critters @playform/compress
// astro.config.mjs
import { defineConfig } from 'astro/config'
import critters from 'astro-critters'
import compress from '@playform/compress'

export default defineConfig({
  integrations: [
    critters(),
    compress({
      CSS: true,
      HTML: true,
      JavaScript: true,
      Image: false,
      SVG: false,
    }),
  ],
})

インテグレーション

astro-critters

クリティカル CSS を自動的に抽出してインライン化します。設定は不要です。

できること:

  • レンダリングされた HTML をスキャンし、ファーストビューの要素を検出します
  • それらの要素に必要な CSS のみをインライン化します
  • 残りは遅延読み込みします

ビルド出力にインライン化された内容が表示されます:

Inlined 40.70 kB (80% of original 50.50 kB) of _astro/index.xxx.css.
@playform/compress

最終ビルドの HTML、CSS、JavaScript を縮小します。

オプション:

compress({
  CSS: true, // Minify CSS
  HTML: true, // Minify HTML
  JavaScript: true, // Minify JS
  Image: false, // Skip if using external image optimization
  SVG: false, // Skip if SVGs are already optimized
})

レイアウトパターン

パフォーマンスを高めるために、Layout.astro を次のように構成します:

---
import '../styles/global.css'
---

<!doctype html>
<html lang="pt-BR">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    
    <style>
      @font-face {
        font-family: 'Inter';
        font-display: swap;
        src: local('Inter');
      }
    </style>

    
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link
      rel="stylesheet"
      href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap"
      media="print"
      onload="this.media='all'"
    />
    <noscript>
      <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap">
    </noscript>

    
    <link rel="preload" as="image" href="/hero.png" fetchpriority="high">

    <title>{title}</title>

    
    <script>
      let loaded = false;
      function loadAnalytics() {
        if (loaded) return;
        loaded = true;
        // Load GTM, analytics, etc.
      }
      ['scroll', 'click', 'touchstart'].forEach(e => {
        document.addEventListener(e, loadAnalytics, { once: true, passive: true });
      });
      setTimeout(loadAnalytics, 5000);
    </script>
  </head>
  <body>
    <slot />
  </body>
</html>

計測

npx lighthouse https://your-site.com --preset=perf --form-factor=mobile

関連項目:

  • perf-lighthouse - 監査の実行、レポートの読み方、予算の設定
  • perf-web-optimization - Core Web Vitals、バンドルサイズ、キャッシュ戦略

チェックリスト

  • astro-critters をインストールして設定済み
  • @playform/compress をインストールして設定済み
  • Google Fonts で media="print" onload パターンを使用
  • サードパーティスクリプトをユーザー操作まで遅延
  • LCP 画像を <head> 内でプリロード

コメント