After running Google page speed test I got suggestion:
Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.
server.ts
//import statements
enableProdMode();
const app = express();
const port = Number(process.env.PORT || 8080);
app.engine('html', ngExpressEngine({
bootstrap: ServerAppModule
}));
app.set('view engine', 'html');
app.set('views', 'src');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
import {
getHomeApi, sendMailApi
} from './backend/api';
app.get('/api/homeData', getHomeApi);
app.post("/api/send", sendMailApi);
app.use(compression());
app.use('',express.static('dist'));
app.use('/assets',express.static('dist/assets'));
app.use('/static',express.static('dist/static', {
index: false
}));
ROUTES.forEach(route => {
app.get(route, (req, res) => {
console.time(`GET: ${req.originalUrl}`);
res.render('../dist/index', {
req: req,
res: res
});
console.timeEnd(`GET: ${req.originalUrl}`);
});
});
app.listen(port,() => {
console.log(`Listening at ${port}`);
});
It suggested me to leverage caching for following static resources.
http://00.000.00.00:8080/api/homeData (expiration not specified)
http://dsms0mj1bbhn4.cloudfront.net/assets/pub/shareaholic.js (10minutes)
So how can I do this? Thank You.