0Pricing
Web Performance Optimization & Lighthouse · Ders

Özel Denetimler ve Doğrulamalar

Projenizle ilgili belirli performans veya en iyi uygulama kurallarını zorunlu kılmak için kendi Lighthouse denetimlerinizi geliştirin.

Özel Denetimler ve Doğrulamalar, CoddyKit'te ücretsiz bir Web Performance Optimization & Lighthouse dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Web Performance Optimization & Lighthouse öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Web Performance Optimization & Lighthouse kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Extend Lighthouse's Power

Welcome to creating custom Lighthouse audits! While Lighthouse offers many built-in checks, sometimes you need to enforce project-specific rules or validate unique performance requirements.

This lesson shows you how to build your own.

Why Create Custom Audits?

Custom audits allow you to tailor Lighthouse to your exact needs. They help you:

  • Enforce Standards: Check for specific coding patterns or component usage.
  • Validate Unique Metrics: Measure performance aspects not covered by default.
  • Ensure Compliance: Verify project-specific accessibility or SEO rules.
  • Automate Checks: Integrate tailored performance feedback directly into your development workflow.

Audit Anatomy: Gatherers & Audits

A custom Lighthouse audit typically has two main parts:

  • Gatherer: This component collects raw data about the page. It runs inside the browser and extracts specific information, like DOM elements, network requests, or JavaScript variables.
  • Audit: This component analyzes the data collected by the gatherer. It applies logic to determine a score, a pass/fail state, and provides recommendations.

Both are then linked in a Lighthouse configuration file.

Building a Gatherer: Data Collection

A gatherer is responsible for collecting data. It extends Lighthouse.Gatherer and uses methods like afterPass to run JavaScript in the page's context.

Let's create a gatherer that checks for a specific <meta> tag.

Gatherer Code Example

This gatherer looks for an <meta name="author"> tag and returns its content. If not found, it returns null.

// gatherers/author-meta-gatherer.js
'use strict';
const Gatherer = require('lighthouse').Gatherer;

class AuthorMetaGatherer extends Gatherer {
  afterPass(options) {
    const driver = options.driver;
    // Evaluate JS in the browser context
    return driver.evaluateAsync(() => {
      const metaTag = document.querySelector('meta[name="author"]');
      return metaTag ? metaTag.content : null;
    });
  }
}

module.exports = AuthorMetaGatherer;

Building an Audit: Evaluation Logic

An audit takes the data provided by gatherers and applies your custom logic. It extends Lighthouse.Audit and implements a static audit method.

This method receives the collected "artifacts" (data) and determines the audit's result.

Audit Code Example

This audit uses the data from our AuthorMetaGatherer to check if the author meta tag is present and has content. It scores 1 (pass) or 0 (fail).

// audits/author-meta-audit.js
'use strict';
const Audit = require('lighthouse').Audit;

class AuthorMetaAudit extends Audit {
  static get meta() {
    return {
      id: 'author-meta-tag',
      title: 'Author meta tag is present',
      failureTitle: 'Author meta tag is missing or empty',
      description: 'Ensures an author meta tag is present for attribution.',
      requiredArtifacts: ['AuthorMetaGatherer'],
    };
  }

  static audit(artifacts) {
    const authorMetaContent = artifacts.AuthorMetaGatherer;
    const passed = !!authorMetaContent && authorMetaContent.trim().length > 0;

    return {
      score: passed ? 1 : 0,
      details: {
        type: 'debuginfo',
        headings: [
          {key: 'content', itemType: 'text', text: 'Author Meta Content'},
        ],
        items: [{content: authorMetaContent || 'Not found'}],
      },
    };
  }
}

module.exports = AuthorMetaAudit;

Integrating into Lighthouse Config

To make Lighthouse aware of your custom gatherer and audit, you need a custom configuration file. This file tells Lighthouse which gatherers to run and which audits to include, often extending the default Lighthouse checks.

// custom-config.js
'use strict';

module.exports = {
  extends: 'lighthouse:default', // Inherit default audits
  gatherers: [
    './gatherers/author-meta-gatherer.js',
  ],
  audits: [
    './audits/author-meta-audit.js',
  ],
  categories: {
    'custom-category': {
      title: 'Custom Checks',
      description: 'Project-specific performance and best practice audits.',
      auditRefs: [
        {id: 'author-meta-tag', weight: 1, group: 'metrics'},
      ],
    },
  },
};

Running Lighthouse with Custom Audits

Finally, you can run Lighthouse programmatically using Node.js, referencing your custom configuration file. This script launches Chrome, runs Lighthouse, and generates a report.

Make sure you have lighthouse and chrome-launcher installed via npm.

// run-custom-audit.js
const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');

(async () => {
  const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
  const options = {
    logLevel: 'info',
    output: 'html',
    onlyCategories: ['custom-category'], // Run ONLY our custom category
    port: chrome.port
  };
  const config = require('./custom-config.js'); // Load your custom config

  const runnerResult = await lighthouse('https://example.com', options, config);

  console.log('Report is done for', runnerResult.lhr.requestedUrl);
  // Accessing your custom audit score:
  const customAuditScore = runnerResult.lhr.audits['author-meta-tag'].score;
  console.log('Author Meta Tag Audit Score:', customAuditScore);

  await chrome.kill();
})();

Custom Audit Components

You've learned about the key pieces needed to build a custom Lighthouse audit.

Which of the following are essential components when creating a custom Lighthouse audit?

Recap: Your Custom Audit Toolkit

You've successfully learned how to extend Lighthouse's capabilities!

By understanding gatherers, audits, and custom configurations, you can now build powerful, project-specific checks. This allows you to enforce unique best practices and gain deeper, tailored insights into your web performance.

Sıkça Sorulan Sorular

“Özel Denetimler ve Doğrulamalar” dersi ücretsiz mi?

Evet — “Özel Denetimler ve Doğrulamalar” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Web Performance Optimization & Lighthouse kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Web Performance Optimization & Lighthouse kursu toplamda 4 dersten oluşur.

“Özel Denetimler ve Doğrulamalar” dersinde ne öğreneceğim?

Projenizle ilgili belirli performans veya en iyi uygulama kurallarını zorunlu kılmak için kendi Lighthouse denetimlerinizi geliştirin. Web Performance Optimization & Lighthouse ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Web Performance Optimization & Lighthouse öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Web Performance Optimization & Lighthouse, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.

“Özel Denetimler ve Doğrulamalar” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Web Performance Optimization & Lighthouse dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Web Performance Optimization & Lighthouse dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. CLI ve Programatik Lighthouse
  2. Özel Denetimler ve Doğrulamalar
  3. Lighthouse'u CI/CD'ye Entegre Etme
  4. Lighthouse ile Performans Bütçeleri
← Web Performance Optimization & Lighthouse Sayfasına Dön