运行Google页面速度测试后,我得到了建议:
在HTTP标头中为静态设置到期日期或最长期限 资源指示浏览器加载以前下载的 来自本地磁盘而非网络的资源。
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}`);
});
它建议我利用缓存来跟踪静态资源。
http://00.000.00.00:8080/api/homeData(未指定过期)
http://dsms0mj1bbhn4.cloudfront.net/assets/pub/shareaholic.js (10分钟)
那我该怎么做呢? 谢谢。