Search code examples
performanceknockout.jsjquery-templates

How can I measure the performance of my jQuery tmpl templates when running under knockout.js


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?


Solution

  • 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.