我有这些视图渲染调用:
router.get('/mcn', (req, res) => {
res.render('product/mcn', { layout: 'product/layout', contactKey: 'mcn' });
});
router.get('/agency', (req, res) => {
res.render('product/agency', { layout: 'product/layout', contactKey: 'agency' });
});
router.get('/esports', (req, res) => {
res.render('product/esports', { layout: 'product/layout', contactKey: 'esports' });
});
router.get('/brand', (req, res) => {
res.render('product/brand', { layout: 'product/layout', contactKey: 'brand' });
});
router.get('/analytics', (req, res) => {
res.render('product/analytics', { layout: 'product/layout', contactKey: 'analytics' });
});
router.get('/rightsmanagement', (req, res) => {
res.render('product/content-id', { layout: 'product/layout', contactKey: 'content-id' });
});
您可能会注意到 - 没有传递动态数据。所以我想知道如何缓存这些视图?像这样的东西:
const pug = require('pug');
{
const templateStr = fs.readFileSync(path.resolve(__dirname +'/../views/product/content-id'));
const fn = pug.compile(templateStr, {});
const html = fn({ layout: 'product/layout', contactKey: 'content-id' });
router.get('/rightsmanagement', (req, res) => {
res.send(html);
});
}
是这样吗?我想我错过了一些标题?没有人知道正确的标题是什么?