Skip to content

Middleware for Connect/Express.js that creates and caches gzipped versions of static files

Notifications You must be signed in to change notification settings

Plombo/static-gzip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

static-gzip

Middleware for Connect or Express that compresses static files using gzip and caches the result on disk for use in future requests.

Based on connect-gzip.

Installation

Install via npm:

$ npm install static-gzip

Usage

staticGzip(root, [options])

Gzips files in a root directory, and then serves them using the send middleware.

If a file under the root path (such as an image) does not have an appropriate MIME type for compression, it will still be passed through to send and served uncompressed. Thus, you can simply use staticGzip in place of connect.static or express.static.

var connect = require('connect'),
    staticGzip = require('static-gzip');

connect.createServer(
  staticGzip(__dirname + '/public')
).listen(3000);


// Only gzip javascript files:
staticGzip(__dirname + '/public', { matchType: /javascript/ })

// Set a maxAge in milliseconds for browsers to cache files
var oneDay = 86400000;
staticGzip(__dirname + '/public', { maxAge: oneDay })

// Store all gzipped files in a directory called 'public-gzip'
staticGzip(__dirname + '/public', { gzipRoot: __dirname + '/public-gzip' })

Options:

  • matchType - A regular expression tested against the file MIME type to determine whether the response should be gzipped or not. As in connect.static, MIME types are determined based on file extensions using node-mime. The default value is /text|javascript|json/.
  • maxAge - Maximum time in milliseconds for browsers to cache files.
  • gzipRoot - Root directory for cached gzip files. Defaults to root if not specified.

Tests

Run the tests with

npm test

License

(The MIT License)

Copyright (c) 2011 Nate Smith <nate@nateps.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Middleware for Connect/Express.js that creates and caches gzipped versions of static files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published