Class: Abqari::Audit::Performance

Inherits:
Rule
  • Object
show all
Defined in:
lib/abqari/audit/performance.rb

Overview

Performance rule. Flags pages whose total image payload would punish a mobile visitor — the most common cause of bad Lighthouse scores on otherwise-clean static sites.

Two thresholds, both per-page:

- Total image bytes on a page (the page's complete image
payload across all `<img>` and `<picture><source>` URLs
pointing at same-origin paths). Warn over 1 MB, error over
3 MB.
- Single-image bytes. A 5 MB hero in an otherwise-light page
defeats the whole pipeline. Warn at 500 KB, error at 1 MB.

Skip pages with no images entirely. Redirect stubs are skipped.

Constant Summary collapse

PAGE_TOTAL_WARN =

1 MB

1_000_000
PAGE_TOTAL_ERROR =

3 MB

3_000_000
SINGLE_WARN =

500 KB

500_000
SINGLE_ERROR =

1 MB

1_000_000

Instance Method Summary collapse

Methods inherited from Rule

#initialize

Constructor Details

This class inherits a constructor from Abqari::Audit::Rule

Instance Method Details

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/abqari/audit/performance.rb', line 24

def run
  html_files.each do |file|
    html = File.read(file, encoding: 'UTF-8')
    next if html =~ /<meta\s+http-equiv=["']refresh/i

    url = page_url(file)
    image_paths = extract_image_urls(html)
    next if image_paths.empty?

    sizes = image_paths.filter_map { |path| size_for(path) }
    flag_heavy_singles(url, sizes)
    flag_heavy_page_total(url, sizes)
  end
end