class Inkcite::Cli::Server::OptimizedImage
Extends Rack::Static to provide dynamic image minification on demand. When an image is requested from the images-optim directory, compression is performed on the desired image if necessary and then the optimized image is returned.
Public Class Methods
new(app, opts)
click to toggle source
Calls superclass method
# File lib/inkcite/cli/server.rb, line 100 def initialize app, opts @email = opts[:email] super end
Public Instance Methods
call(env)
click to toggle source
Calls superclass method
# File lib/inkcite/cli/server.rb, line 105 def call env # e.g. images-optim/my-image.jpg path = env['PATH_INFO'] # Minify the image if the source version in images/ is newer # or if the configuration file controlling optimization has # been updated since the last time the image was requested. ImageMinifier.minify(@email, File.basename(path), false) if can_serve(path) # Let the super method handle the actual serving of the image. res = super # Install cache control into the response. Tried using res[1][Rack::CACHE_CONTROL] = NO_CACHE res end