如何测量 jQuery tmpl 模板在 knockout.js 下运行时的性能

发布于 2025-01-08 10:34:11 字数 464 浏览 5 评论 0原文

我有一个页面使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单 2025-01-15 10:34:11

我不确定 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文