Sha256: f9f97e8260d2ccc083852b36c7ae56e9cc04cfe858239cfb71a203021514f37b

Contents?: true

Size: 740 Bytes

Versions: 8

Compression:

Stored size: 740 Bytes

Contents

# frozen_string_literal: true
module ThemeCheck
  class AssetSizeCSSStylesheetTag < LiquidCheck
    include RegexHelpers
    severity :error
    category :liquid, :performance
    doc docs_url(__FILE__)

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

    def on_variable(node)
      used_filters = node.value.filters.map { |name, *_rest| name }
      return unless used_filters.include?("stylesheet_tag")
      file_size = href_to_file_size('{{' + node.markup + '}}')
      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

8 entries across 8 versions & 1 rubygems

Version Path
theme-check-1.5.2 lib/theme_check/checks/asset_size_css_stylesheet_tag.rb
theme-check-1.5.1 lib/theme_check/checks/asset_size_css_stylesheet_tag.rb
theme-check-1.5.0 lib/theme_check/checks/asset_size_css_stylesheet_tag.rb
theme-check-1.4.0 lib/theme_check/checks/asset_size_css_stylesheet_tag.rb
theme-check-1.3.0 lib/theme_check/checks/asset_size_css_stylesheet_tag.rb
theme-check-1.2.0 lib/theme_check/checks/asset_size_css_stylesheet_tag.rb
theme-check-1.1.0 lib/theme_check/checks/asset_size_css_stylesheet_tag.rb
theme-check-1.0.0 lib/theme_check/checks/asset_size_css_stylesheet_tag.rb