Class: ThemeCheck::AssetPreload

Inherits:
HtmlCheck show all
Defined in:
lib/theme_check/checks/asset_preload.rb

Constant Summary

Constants inherited from HtmlCheck

HtmlCheck::START_OR_END_QUOTE

Constants inherited from Check

Check::CATEGORIES, Check::SEVERITIES, Check::SEVERITY_VALUES

Instance Attribute Summary

Attributes inherited from Check

#ignored_patterns, #offenses, #options, #theme

Instance Method Summary collapse

Methods included from ChecksTracking

#inherited

Methods inherited from Check

#==, #add_offense, all, can_disable, #can_disable?, categories, #categories, category, #code_name, doc, #doc, docs_url, #ignore!, #ignored?, #severity, severity, #severity=, #severity_value, severity_value, single_file, #single_file?, #to_s, #whole_theme?

Methods included from JsonHelpers

#format_json_parse_error, #pretty_json

Instance Method Details



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/theme_check/checks/asset_preload.rb', line 8

def on_link(node)
  return if node.attributes["rel"]&.downcase != "preload"
  case node.attributes["as"]&.downcase
  when "style"
    add_offense("For better performance, prefer using the preload argument of the stylesheet_tag filter", node: node)
  when "image"
    add_offense("For better performance, prefer using the preload argument of the image_tag filter", node: node)
  else
    add_offense("For better performance, prefer using the preload_tag filter", node: node)
  end
end