Last active
January 12, 2016 07:54
-
-
Save kavitshah8/612ce6984de6e0f4ff95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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 })); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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