Class: Rack::PageSpeed::Filters::CombineCSS

Inherits:
Rack::PageSpeed::Filter
  • Object
show all
Defined in:
lib/rack/pagespeed/filters/combine_css.rb

Instance Method Summary collapse

Instance Method Details

#execute!(document) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rack/pagespeed/filters/combine_css.rb', line 11

def execute! document
  nodes = document.css('link[rel="stylesheet"][href]')
  return false unless nodes.count > 0
  groups = group_siblings topmost_of_sequence(nodes)
  groups.each do |group|
    save group
    merged = merge group, document
    group.first.before merged
    group.map { |node| node.remove }
  end
end