資訊中心:響應式與行動裝置工具與命令:可直接復用
一、DevTools 設備模式
- 打開開發者工具。
- 切換設備工具欄。
- 依次選 320、375、414、768、1024。
- 檢查橫向滾動、點擊目標、字型、圖片。
- 打開網路限速模擬弱網。
二、Lighthouse
移動模式(預設):
npx lighthouse https://example.com/ --output html --output-path ./lh-mobile.html
桌面模式:
npx lighthouse https://example.com/ --preset=desktop --output html --output-path ./lh-desktop.html
重點看:
- LCP、INP、CLS。
- 圖片體積。
- 未使用 JS/CSS。
- 字型載入。
三、Playwright 多視口
npx playwright install chromium
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const widths = [320, 375, 414, 768, 1024, 1440];
for (const width of widths) {
const page = await browser.newPage({ viewport: { width, height: 900 } });
await page.goto('https://example.com/', { waitUntil: 'networkidle' });
const overflow = await page.evaluate(() => document.documentElement.scrollWidth > window.innerWidth);
console.log(width, 'horizontal_overflow=', overflow);
await page.screenshot({ path: `shot-${width}.png`, fullPage: true });
await page.close();
}
await browser.close();
})();
四、瀏覽器控制台查溢出
[...document.querySelectorAll('*')]
.filter(el => el.scrollWidth > document.documentElement.clientWidth)
.slice(0, 20)
.forEach(el => console.log(el.tagName, el.className, el.scrollWidth));
找出具體元素,比盲改 CSS 快。
五、響應頭與快取
curl -I https://example.com/
curl -I https://example.com/assets/app.css
看:
content-typecache-controlcontent-encodingserver-timing
六、圖片檢查
curl -I https://example.com/hero.jpg
確認:
- 實際尺寸。
- 是否 WebP/AVIF。
- 快取頭。
- 是否按需返回不同尺寸(CDN)。
七、CSS 斷點檢查
/* 移動優先,按內容切換 */
@media (min-width: 640px) { /* 平板 */ }
@media (min-width: 1024px) { /* 桌面 */ }
不要爲每個機型寫一套。
八、測試矩陣
| 寬度 | 重點 |
|---|---|
| 320 | 最小屏、溢出 |
| 375 | 主流手機 |
| 414 | 大屏手機 |
| 768 | 豎屏平板 |
| 1024 | 橫屏平板/小筆記型電腦 |
| 1440 | 桌面 |
九、記錄結果
儲存:
- Lighthouse 報告。
- 各寬度截圖。
- 溢出元素清單。
- 修復前後對比。
邊界
工具能發現問題,不能替你做設計決策。命令按專案技術棧調整,Node 工具需本地有環境。
相關閱讀: