Class: Rack::PageSpeed::Filters::InlineJavaScripts

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

Instance Method Summary collapse

Instance Method Details

#execute!(document) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rack/pagespeed/filters/inline_javascripts.rb', line 5

def execute! document
  nodes = document.css('script[src]')
  return false unless nodes.count > 0
  nodes.each do |node|
    file = file_for node
    next if !file or file.stat.size > (@options[:max_size] or 2048)
    inline = Nokogiri::XML::Node.new 'script', document
    inline.content = file.read
    node.before inline
    node.remove
  end
end