Load javascript not tied to page element RRS feed

  • Question

  • Hi all,


    I created an HTML page e.g. detail.html and its counterpart javascript detail.js.

    In the detail.html I define a namespace "MyApp" with 1 member called "myDetail : page"  and also within a page var I render some nice HTML.

    I then include detail.html into another page e.g. <div class="backForwards" data-win-control="MyApp.myDetail">hi</div>

    So far so good. Where the DIV is set, the detail.html gets rendered.

    I then within detail.html have a line saying <script src="/js/ShoppingCart.js"></script>

    This js file contains a couple of functions which are defined within the namespace
        WinJS.Namespace.defineWithParent(MyApp, 'Settings', {
            getMyCart: getMyCart,
            setMyCart: setMyCart,
            hello : helloString

    When I try to access MyApp.Settings.hello, it does not work. It seems the javascript never got loaded and the namespace members are undefined.

    When I add this code to default.js it works, but because of clear code separation I would like to store it separately. How can I get the app to load the separately defined js other than importing the javascript using the script tag? (do I have to force it to load using data-win-control or so?)


    Thursday, April 4, 2013 11:26 AM


All replies

  • Hi Thomas,

    What is your concern of 'but because of clear code separation'?

    Do you understand all the JS stays loaded regardless of when/how you do it so this is an academic exercise?


    Jeff Sanders (MSFT)

    Thursday, April 4, 2013 6:38 PM
  • Hi Jeff,

    Thanks for the reply. Turned out to be my error. I was not referencing the correct JavaScript file name in one of the HTML pages.

    Sorry for that.

    Best regards,


    Thursday, April 11, 2013 8:06 AM
  • Meaning every js found in the package is loaded when the app is started?
    Thursday, April 11, 2013 4:23 PM
  • Hi Phil,

    Read this article for a good understanding or how, why when you want your JavaScript Loaded:



    Jeff Sanders (MSFT)

    Thursday, April 11, 2013 5:19 PM
  • Thanks Jeff, I know this article. I was and still am confused about your "Do you understand all the JS is loaded regardless of when/how you do it "

    What do you mean by that? The article clearly says that not everything is loaded, if I don't do it.

    Friday, April 12, 2013 9:55 AM
  • Let me fix it:

    "Do you understand all the JS stays loaded regardless of when/how you do it "

    Jeff Sanders (MSFT)

    Friday, April 12, 2013 6:49 PM
  • This makes sense now, although I already knew that :)
    Monday, April 15, 2013 9:06 AM