Web Performance Optimization & Lighthouse · บทเรียน

งบประมาณประสิทธิภาพด้วย Lighthouse

กำหนดและบังคับใช้งบประมาณประสิทธิภาพ เพื่อให้ตรวจสอบขนาดและขีดจำกัดของตัวชี้วัดโดยอัตโนมัติ และป้องกันประสิทธิภาพถดถอยก่อนถึงระบบจริง

บทเรียน 4 จาก 413 ขั้นตอน

งบประมาณประสิทธิภาพด้วย Lighthouse เป็นบทเรียน Web Performance Optimization & Lighthouse ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Web Performance Optimization & Lighthouse และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Web Performance Optimization & Lighthouse มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

What Is a Performance Budget?

A performance budget is a set of agreed limits, such as max JavaScript size or a minimum LCP, that the team commits not to exceed. It turns vague goals into enforceable thresholds.

Why Budgets Matter

Without budgets, performance erodes silently as features pile on. A budget makes regressions visible and blocking, shifting performance left into development.

Two Kinds of Budgets

  • Resource budgets: byte size and request counts per type (script, image, total).
  • Timing budgets: metric thresholds like LCP, TBT, CLS.

The budget.json File

Lighthouse reads a budget.json describing resource and timing limits. It then flags any audited page that exceeds them.

[{
  "resourceSizes": [
    { "resourceType": "script", "budget": 170 },
    { "resourceType": "total", "budget": 500 }
  ]
}]

Adding Timing Budgets

Timings are listed alongside sizes. Values are in milliseconds for time metrics.

[{
  "timings": [
    { "metric": "largest-contentful-paint", "budget": 2500 },
    { "metric": "interactive", "budget": 3800 }
  ]
}]

Running with a Budget

Pass the budget file to the Lighthouse CLI. Exceeded items appear in the report's Budgets section.

lighthouse https://example.com --budget-path=./budget.json --output=json --output-path=./report.json

Enforcing in CI with LHCI

Lighthouse CI (lhci) can assert budgets and fail the build when limits are breached, so regressions never merge.

// lighthouserc.json
{
  "ci": {
    "assert": {
      "assertions": {
        "resource-summary:script:size": ["error", { "maxNumericValue": 174080 }]
      }
    }
  }
}

Warn vs Error Levels

Assertions support warn and error levels. Start new budgets as warnings to gather data, then promote to errors once the team is confident.

Setting Realistic Limits

Base budgets on current measurements plus a small margin, or on competitor benchmarks. Budgets that are impossible to meet get ignored; budgets that are too loose never fire.

Tracking Over Time

The LHCI server stores historical results so you can chart metric and size trends and tighten budgets gradually as performance improves.

Workflow Summary

  • Define resource and timing budgets.
  • Run them locally via CLI.
  • Assert them in CI with LHCI.
  • Start as warnings, then enforce as errors.

Quick Check

You want a pull request to fail automatically when the script bundle grows beyond a set size. What achieves this?

Recap

You learned to set resource and timing budgets in budget.json, run them with the Lighthouse CLI, and enforce them in CI via Lighthouse CI assertions. Start with warnings, promote to errors, and track trends to keep performance from regressing.

เริ่มต้นได้ฟรี

เรียนรู้ Web Performance Optimization & Lighthouse ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “งบประมาณประสิทธิภาพด้วย Lighthouse” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “งบประมาณประสิทธิภาพด้วย Lighthouse” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Web Performance Optimization & Lighthouse ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Web Performance Optimization & Lighthouse มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “งบประมาณประสิทธิภาพด้วย Lighthouse”

กำหนดและบังคับใช้งบประมาณประสิทธิภาพ เพื่อให้ตรวจสอบขนาดและขีดจำกัดของตัวชี้วัดโดยอัตโนมัติ และป้องกันประสิทธิภาพถดถอยก่อนถึงระบบจริง คุณปฏิบัติ Web Performance Optimization & Lighthouse ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Web Performance Optimization & Lighthouse หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Web Performance Optimization & Lighthouse บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “งบประมาณประสิทธิภาพด้วย Lighthouse” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Web Performance Optimization & Lighthouse นี้ได้ไหม

ได้ บทเรียน Web Performance Optimization & Lighthouse ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. CLI และ Lighthouse แบบใช้โปรแกรม
  2. การตรวจสอบและการยืนยันแบบกำหนดเอง
  3. การผสานรวม Lighthouse เข้ากับ CI/CD
  4. งบประมาณประสิทธิภาพด้วย Lighthouse
← กลับไปที่ Web Performance Optimization & Lighthouse