GithubHelp home page GithubHelp logo

alexxnica / connect-gzip-static Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pirxpilot/connect-gzip-static

0.0 1.0 0.0 35 KB

connect middleware for statically compressed files

License: MIT License

Makefile 1.30% JavaScript 98.70%

connect-gzip-static's Introduction

NPM version Build Status Dependency Status

connect-gzip-static

Middleware for connect: serves compressed files if they exist, falls through to connect-static if they don't, or if browser does not send 'Accept-Encoding' header.

You should use connect-gzip-static if your build process already creates compressed (using gzip or brotli) files. If you want to compress your data on the fly use compression middleware. And if you want to compress your files dynamically you may want to look up connect gzip.

Installation

  $ npm install connect-gzip-static

Options

gzip-static is meant to be a drop in replacement for connect static middleware. Use the same options as you would with connect static.

Usage

var gzipStatic = require('connect-gzip-static');
var oneDay = 86400000;

connect()
  .use(gzipStatic(__dirname + '/public'))

connect()
  .use(gzipStatic(__dirname + '/public', { maxAge: oneDay }))

How it works

We start by locating all compressed files (ie. files with .gz and .br extensions) in root directory. All HTTP GET and HTTP HEAD requests with Accept-Encoding header set to gzip are checked against the list of compressed files and, if possible, fulfilled by returning the compressed versions. If compressed version is not found or if the request does not have an appropriate Accept- Encoding header, the request is processed in the same way as standard static middleware would handle it.

Debugging

This project uses debug module. To enable the debug log, just set the debug enviromental variable:

DEBUG="connect:gzip-static"

License

MIT © Damian Krzeminski

connect-gzip-static's People

Contributors

pirxpilot avatar alfred-nsh avatar steverandy avatar melitele avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.