在将Angular应用的性能最佳化后,我将Angular与SSR Node.js服务器一起使用时,通过渲染HTML大约需要16 s的响应时间
我试图压缩html
i将@ nguniversal / express-engine与延迟加载(Angular 6)一起使用 和Express应用
我的代码
enableProdMode();
const app = express();
const PORT = process.env.PORT || 5410;
const arBundle = require('./server/ar/main');
const enBundle = require('./server/en/main');
export const languageEngines = [{
id: 'en',
base: '/en'
},
{
id: 'ar',
base: '/ar'
},
{
id: 'en',
base: '/'
},
];
app.engine('html', ngExpressEngine({
bootstrap: enBundle.AppServerModuleNgFactory,
providers: [
provideModuleMap(enBundle.LAZY_MODULE_MAP)
]
}));
app.set('view engine', 'html');
app.set('views', join(__dirname, 'browser'));
app.get('*.*', express.static((__dirname + '/browser'), {
maxAge: '1y'
}));
languageEngines.forEach(languageEngine => {
app.get(languageEngine.base + "*", function (req, res) {
res.render(__dirname + "/browser/" + languageEngine.id + "/index.html", {
req: req,
res: res
});
});
});