We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
script
<script id="demo_tmpl" type="text/html"> <div>模板内容...</div> </script>
demo_tmpl.html放到inc目录下:
<script id="demo_tmpl" type="text/html"> #parse("inc/path/to/demo_tmpl.html") </script>
demo_tmpl.html放到templates目录下:
var demoTmpl = require('text!templates/path/to/demo_tmpl.html'); // ...
将来构建工具会把模板内容内联进js文件里,如下:
var demoTmpl = 'demo_tmp.html的内容...'; // ...
⚠️ 因为构建工具会把templates里的文件内容内联到js里,所以构建时会排除templates目录,所以如果想在html页面里#parse引入js模板文件,请将js模板放到inc目录下
var demoTmpl = '<div>'+ '<p>' + '<span>' + item +'</span>' + '</p>' + '</div>';
DOM操作很慢,改变DOM结构和布局都会产生重排(reflow),重排又一定会导致重绘(repaint),所以尽量减少重排和重绘。
哪些操作会导致重排或者重绘:https://csstriggers.com/
👉 推荐阅读:https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing?hl=zh-cn
The text was updated successfully, but these errors were encountered:
No branches or pull requests
简单模板能直接写在页面里,放到
script
标签里复杂的模板请写到单独的文件
demo_tmpl.html放到inc目录下:
demo_tmpl.html放到templates目录下:
将来构建工具会把模板内容内联进js文件里,如下:
👎 不好的写法
优化DOM操作,提高渲染效率
DOM操作很慢,改变DOM结构和布局都会产生重排(reflow),重排又一定会导致重绘(repaint),所以尽量减少重排和重绘。
👉 推荐阅读:https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing?hl=zh-cn
The text was updated successfully, but these errors were encountered: