Module: Middleman::Extensions::Gzip

Defined in:
middleman-more/lib/middleman-more/extensions/gzip.rb

Overview

This extension Gzips assets and pages when building. Gzipped assets and pages can be served directly by Apache or Nginx with the proper configuration, and pre-zipping means that we can use a more agressive compression level at no CPU cost per request.

Use Nginx's gzip_static directive, or AddEncoding and mod_rewrite in Apache to serve your Gzipped files whenever the normal (non-.gz) filename is requested.

Pass the :exts options to customize which file extensions get zipped (defaults to .html, .htm, .js and .css.

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary (collapse)

Class Method Details

+ (Object) registered(app, options = {}) Also known as: included



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'middleman-more/lib/middleman-more/extensions/gzip.rb', line 20

def registered(app, options={})
  exts = options[:exts] || %w(.js .css .html .htm)
  
  app.send :include, InstanceMethods

  app.after_build do |builder|
    Find.find(self.class.inst.build_dir) do |path|
      next if File.directory? path
      if exts.include? File.extname(path)
        new_size = gzip_file(path, builder)
      end
    end
  end
end