class Rack::PageSpeed::Filters::InlineJavaScripts

Public Instance Methods

execute!(document) click to toggle source
# 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|
    status, headers, body = content_for node
    next if status != 200 or headers['Content-Length'].to_i > (@options[:max_size] or 2048)
    inline = Nokogiri::XML::Node.new 'script', document
    full_body = ""; body.each do |part| full_body << part end
    inline.content = JSMin.minify(full_body)
    node.before inline
    node.remove
  end
end