SPA/MVVM: Adding templates using Require.js !text

2 posts, 0 answers
  1. Matthew
    Matthew avatar
    10 posts
    Member since:
    Nov 2014

    Posted 07 Dec 2014 Link to this post

    Hey everyone,

    I'm migrating from KO.js where knockout is able to parse the DOM when you add the view model to the element. However, I love how Kendo MVVM uses templates using script tags, almost in a backbone fashion. I was  watching the tech chat from July 24, 2013 on YouTube and they mentioned using the !text plugin from Require.js to load the script tags to the DOM. My question is, is this a good practice and what are the performance gains of adding the templates after the DOM loads compared to downloading them on the initial request? I realize that this may be more of a Require question, but I'm hoping that you can help in identifying the best practices. The application I'm working on now has about 200 templates. I'm showing a landing page while kendo and my other libs download, and some initial ajax calls are processed using nested require calls. My concern is that by loading the templates after the DOM loads adds an additional layer of complexity and could potentially cause the app to fail to load. Is the extra added error handling worth any possible performance gains? Maybe this is an old school concern, but as a trained network engineer, I would rather make the least amount of calls as possible.

    Any help is greatly appreciated.

    --Matt B
  2. Petyo
    Petyo avatar
    2436 posts

    Posted 08 Dec 2014 Link to this post

    Hello Matthew,

    using separate requests speeds up the boot time (less things to download), but decrease the app "responsiveness", as each navigation may result in an additional request to fetch the UI. Both approaches make sense in certain cases. A thing you may try is to compile the resources with r.js and see how the app behaves when everything is loaded upfront. 

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top