This approach serves pre gzipped Angular files and sets client-side caching for static files to 1 year
var express = require('express'); var path = require('path'); var cookieParser = require('cookie-parser'); var logger = require('morgan'); var mime = require('mime-types'); //var compression = require('compression'); var expressStaticGzip = require("express-static-gzip"); var app = express(); app.use(logger('dev')); app.use(express.json()); app.use(express.urlencoded({extended: false})); app.use(cookieParser()); //app.use(compression()); app.use("/", expressStaticGzip(path.join(__dirname, 'public'), { maxAge: "365d", setHeaders: function (res, path) { if (mime.lookup(path) === 'text/html') { res.setHeader('Cache-Control', 'public, max-age=0') } } })); //app.use(express.static(path.join(__dirname, 'public'), {maxAge: 31536000})); app.get('*', function (req, res, next) { var file = path.join(__dirname, 'public', 'index.html'); res.sendFile(file); }); module.exports = app;