-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
第九节课问题收集 #20
Comments
想问下老师对于 Node 作为 API 和静态页面中间层的处理。场景是既要满足SEO,又可以体现服务端渲染的首屏性能。类似的用户登录态 COOKIE/Token 该怎么维护,怎么处理既存在模板渲染又存在 JS 操作 DOM的情况。 比方说用ejs来初始化渲染一个列表,但是列表可能会动态变化,这时候又需要 JS 利用 AJAX 来获取数据后进行 DOM 操作这个列表。感觉很多重复性的工作可能会做两遍。如果项目的规模没有必要做类似 React Vue 的同构的话,怎么去平衡的处理「模板」和 「AJAX」.d 这里有个代码示例,一个 // node
async list() {
const res = await this.ctx.curl(
'/sth/list',
{
dataType: 'json',
},
);
await this.ctx.render('list.ejs', {
dataList: res.data || [],
});
} 一个 ejs <% dataList.list.forEach(function(data) {%>
<p>xxxx</p>
<%})%> 还有 AJAX const res = await fetch('/sth/list')
const listId = document.getElementById('list-id');
res.list.forEach(() => {
// replace or append html string...
}) |
@Beace ejs也有浏览器版引擎啊,然后利用webpack引入模版不就好了~ |
@miniflycn 嗯嗯,这个可以 👍。但是说到 webpack,毕竟是个多页面应用,我这里用 html-webpack-plugin 去注入生成的 CSS 和 JS 的时候,它识别不了 ejs const htmlPlugins = files.map(
file =>
new HtmlWebpackPlugin({
inject: 'body',
template: `!!raw-loader!${path.join(
__dirname,
`./client/pages/${file.filename}.ejs`,
)}`,
filename: path.join(__dirname, `./app/view/${file.filename}.ejs`),
chunks: file.chunks,
}),
);
module.exports = {
entry: {
page1: xxxx.js,
page2: xxx.js,
...xxxx,
}
....
plugins: [
...,
...htmlPlugins,
]
} 这样的做法是最好的方式吗? |
@Beace 参考:
1、可以换一个支持 include 的 loader 试试; |
问题1:老师在公司中会用类似Egg这样的框架,还是在koa这种基础上搭建。另外会用这种egg这种约定式的项目结构吗?,还是自己灵活配置的? 问题2:一次请求,nginx一层logs,pm2一层log,log4自己打一层log,我不知道这样描述是否准确,多层log在实际项目中怎么管理?遇到问题怎么看log。 问题3:在公司里面,怎么发布 部署?能否说下流程。(版本 灰度发布)。如果有空也说下前端项目的发布部署可以吗?感觉我们公司的部署方式太low |
@javenchen 可以答疑的时候聊聊 |
No description provided.
The text was updated successfully, but these errors were encountered: