コラム・情報:响应式与移动端工具与命令:可直接复用
一、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 工具需本地有环境。
相关阅读: