Sha256: e5275cfebac212a4d7400d98df75d9e75b9bce6027cd113b0b065b3ac6d22581

Contents?: true

Size: 709 Bytes

Versions: 5

Compression:

Stored size: 709 Bytes

Contents

# frozen_string_literal: true
module ThemeCheck
  class AssetSizeCSS < HtmlCheck
    include RegexHelpers
    severity :error
    category :html, :performance
    doc docs_url(__FILE__)

    attr_reader :threshold_in_bytes

    def initialize(threshold_in_bytes: 100_000)
      @threshold_in_bytes = threshold_in_bytes
    end

    def on_link(node)
      return if node.attributes['rel'] != "stylesheet"
      file_size = href_to_file_size(node.attributes['href'])
      return if file_size.nil?
      return if file_size <= threshold_in_bytes
      add_offense(
        "CSS on every page load exceeding compressed size threshold (#{threshold_in_bytes} Bytes)",
        node: node
      )
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
theme-check-1.5.2 lib/theme_check/checks/asset_size_css.rb
theme-check-1.5.1 lib/theme_check/checks/asset_size_css.rb
theme-check-1.5.0 lib/theme_check/checks/asset_size_css.rb
theme-check-1.4.0 lib/theme_check/checks/asset_size_css.rb
theme-check-1.3.0 lib/theme_check/checks/asset_size_css.rb