如何测量 jQuery tmpl 模板在 knockout.js 下运行时的性能
我有一个页面使用 Knockout.js 和多个 tmpl 模板。我相信与模板有关的某些事情会降低页面的性能。
<script type="text/x-jquery-tmpl" id="template1">
</script>
<script type="text/x-jquery-tmpl" id="template2">
// I call template 3
</script>
<script type="text/x-jquery-tmpl" id="template3">
</script>
...etc...
由于我有很多模板,其中一些模板调用其他模板,我如何找出哪个模板造成了性能问题?
例如,我可以在每个模板中运行一些 JavaScript 来测量它们花费的时间渲染?
I have a page that uses knockout.js with several tmpl templates. I believe something to do with the templates is killing the page's performance.
<script type="text/x-jquery-tmpl" id="template1">
</script>
<script type="text/x-jquery-tmpl" id="template2">
// I call template 3
</script>
<script type="text/x-jquery-tmpl" id="template3">
</script>
...etc...
As I have many templates, some which call other templates, how do I find out which template is creating the performance problem?
For example, can I run some javascript in each template to measure how long they are taking to render?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定 knockout.js 中是否有任何内置工具可以执行此操作,但您可以尝试调整 knockout.js 的源代码并添加所需的日志记录。模板绑定在此处定义。找到“ko.bindingHandlers['template'] = ...”并在“update”函数中添加您的日志记录。
I am not sure if there are any built-in tools to do that in knockout.js, but you could try tweaking the source code of knockout.js and adding the logging you need. Template binding is defined here. Find "ko.bindingHandlers['template'] = ..." and add your logging in 'update' function.