Claude Code के साथ Implementation
Claude Code का उपयोग करके implementation सीखें। Practical tips और code examples शामिल हैं।
Webfontのoptimizationでdisplay速度を改善
Webfontはデザインの品質を高めますが、optimizationしないとdisplay速度に大きく影響し है।Claude Code का उपयोग करके、fontのサブセット化 सेロード戦略 तकefficientlyimplementationでき है।
font-displayのappropriateなsettings
> Webfontの読み込みをoptimizationして。
> FOUTとFOITを防ぎ、user体験を損なわないsettingsにして。
/* font-displayの使い分け */
@font-face {
font-family: 'Noto Sans JP';
src: url('/fonts/NotoSansJP-Regular.woff2') format('woff2');
font-weight: 400;
font-style: normal;
font-display: swap; /* テキストを即座にdisplayし、font読み込みबादに差し替え */
}
@font-face {
font-family: 'Noto Sans JP';
src: url('/fonts/NotoSansJP-Bold.woff2') format('woff2');
font-weight: 700;
font-style: normal;
font-display: swap;
}
/* ヒーロー見出し आदिのimportantfont */
@font-face {
font-family: 'Display Font';
src: url('/fonts/display.woff2') format('woff2');
font-weight: 700;
font-display: optional; /* networkが遅いcase मेंシステムfontで代替 */
}
Preloadによる先読み
<head>
<!-- クリティカルなfontをpreload -->
<link rel="preload" href="/fonts/NotoSansJP-Regular.woff2"
as="font" type="font/woff2" crossorigin />
<link rel="preload" href="/fonts/NotoSansJP-Bold.woff2"
as="font" type="font/woff2" crossorigin />
</head>
日本語fontのサブセット化
> 日本語fontをज़रूरीな文字だけにサブセット化して。
> JIS第一水準・第二水準と常用漢字をカバーして。
// scripts/subset-font.ts
import { execSync } from 'child_process';
import { readFileSync, writeFileSync } from 'fs';
// pyftsubsetを使ったサブセット化
function subsetFont(inputPath: string, outputPath: string, unicodeRange: string) {
execSync(
`pyftsubset ${inputPath} ` +
`--output-file=${outputPath} ` +
`--flavor=woff2 ` +
`--layout-features='*' ` +
`--unicode-range="${unicodeRange}"`
);
}
// Unicode範囲の分割(チャンク化)
const chunks = [
{ name: 'latin', range: 'U+0000-007F,U+2000-206F,U+2070-209F' },
{ name: 'kana', range: 'U+3000-303F,U+3040-309F,U+30A0-30FF,U+FF00-FFEF' },
{ name: 'kanji-1', range: 'U+4E00-5FFF' },
{ name: 'kanji-2', range: 'U+6000-7FFF' },
{ name: 'kanji-3', range: 'U+8000-9FFF' },
];
for (const chunk of chunks) {
subsetFont(
'src/fonts/NotoSansJP-Regular.ttf',
`public/fonts/NotoSansJP-${chunk.name}.woff2`,
chunk.range
);
}
/* Unicode-rangeによる分割読み込み */
@font-face {
font-family: 'Noto Sans JP';
src: url('/fonts/NotoSansJP-latin.woff2') format('woff2');
unicode-range: U+0000-007F, U+2000-206F;
font-display: swap;
}
@font-face {
font-family: 'Noto Sans JP';
src: url('/fonts/NotoSansJP-kana.woff2') format('woff2');
unicode-range: U+3000-303F, U+3040-309F, U+30A0-30FF;
font-display: swap;
}
@font-face {
font-family: 'Noto Sans JP';
src: url('/fonts/NotoSansJP-kanji-1.woff2') format('woff2');
unicode-range: U+4E00-5FFF;
font-display: swap;
}
可変font(Variable Fonts)のutilization
@font-face {
font-family: 'Inter Variable';
src: url('/fonts/Inter-Variable.woff2') format('woff2-variations');
font-weight: 100 900;
font-style: normal;
font-display: swap;
}
body {
font-family: 'Inter Variable', sans-serif;
font-weight: 400;
}
/* एकのfileで全ウェイトをカバー */
h1 { font-weight: 800; }
h2 { font-weight: 700; }
h3 { font-weight: 600; }
.caption { font-weight: 300; }
フォールバックfontのメトリクス調整
/* CLSを防ぐためのsize調整 */
@font-face {
font-family: 'Adjusted Arial';
src: local('Arial');
size-adjust: 105%;
ascent-override: 90%;
descent-override: 20%;
line-gap-override: 0%;
}
body {
font-family: 'Noto Sans JP', 'Adjusted Arial', sans-serif;
}
font読み込み状態の監視
// Font Loading APIで読み込み完了を検知
async function waitForFonts() {
if ('fonts' in document) {
await document.fonts.ready;
document.documentElement.classList.add('fonts-loaded');
}
}
// 特定fontの読み込み confirm
async function loadCriticalFont() {
const font = new FontFace(
'Noto Sans JP',
'url(/fonts/NotoSansJP-Regular.woff2)'
);
try {
const loaded = await font.load();
document.fonts.add(loaded);
console.log('font読み込み完了');
} catch (err) {
console.error('font読み込み失敗:', err);
}
}
Summary
fontoptimizationはperformanceoptimizationのमेंでもविशेष रूप से効果がबड़ा施策 है।Claude Code का उपयोग करके、サブセット化スクリプト सेunicode-range分割 तकefficientlyimplementationでき है।画像optimizationと並行して取り組む बातで、pageのdisplay速度を大幅に改善でき है।Google Fontsのoptimizationके बारे मेंはweb.devभी reference के लिए देखें。
Related Posts
Claude Code Hooks में Mastery: Auto-Format, Auto-Test, और बहुत कुछ
Claude Code hooks से auto-formatting और auto-testing setup करना सीखें। Practical configuration examples और real-world use cases शामिल हैं।
Claude Code MCP Server Setup और Practical Use Cases
Claude Code की MCP server capabilities की comprehensive guide। External tools connect करना, servers configure करना, और real-world integration examples सीखें।
CLAUDE.md लिखने की Complete Guide: Project Configuration की Best Practices
Effective CLAUDE.md files लिखने की thorough guide। अपना tech stack, conventions, और project structure communicate करना सीखें और Claude Code की output quality maximize करें।