Skip to content

Instantly share code, notes, and snippets.

@kavitshah8
Last active January 12, 2016 07:54
Show Gist options
  • Save kavitshah8/612ce6984de6e0f4ff95 to your computer and use it in GitHub Desktop.
Save kavitshah8/612ce6984de6e0f4ff95 to your computer and use it in GitHub Desktop.
'use strict';
var express = require('express');
var compression = require('compression');
var app = express();
var oneYear;
// gzip the static resources before seding to browser, if the browser supports gzip compression
// Verification : Observe the response header Content-Encoding: gzip
app.use(compression());
// Serves the static resources from public by mounting the path '/'.
// Caches the static files for a year.
// Verification :
// 1. Requesting the page for the first time should have 200 response
// 2. Requesting the page for again by doing the refresh (ctrl + R) should have 304 response
// 3. Requesting the page again by doing the hard refresh (ctrl + shift + R) should have 200 response
oneYear = 1 * 365 * 24 * 60 * 60 * 1000;
app.use('/', express.static(__dirname + '/public/', { maxAge: oneYear }));
{
"name": "gzipdemo",
"version": "0.0.1",
"main": "server.js",
"dependencies": {
"express": "^4.4.5"
},
"devDependencies": {
"compression": "^1.6.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment