Fix: spurious issue where knockout bindings sometimes fail to apply

in case this helps anyone:

recently have been using knockout + knockout-kendo + kendo to make an instant search UI.
the experience has been pretty good - really nice performance ...

however I had a spurious issue, where sometimes on page load, the knockout binding would fail to succeed.

from testing, it seemed that at the time of attempted binding:

jQuery was able to find the relevant div
however knockout bind failed, as if it could not 'see' the div

Diagnosing:
- Google Chrome browser -> Elements view -> copied ALL the HTML DOM into a compare tool
- repeated this step for a page load that was OK and for a page load that had knockout FAILING

Used the compare tool to compare.

Found that the list of loaded modules was different.

In particular:
- on some page loads, jQuery was being loaded twice.

Cause:
- page was loading jQuery using a HTML script tag, AND a require.js module dependency

Fix:
- removed the require.js module dependency (too hard to change the page)

Obviously this might sound trivial - but posting just in case it helps anyone, and in case it helps me again!

Comments