locked
Metro Apps eval and script tags RRS feed

  • Question

  • We are using some code that is generated on the fly based on some setting to provide optimal performances by only include fragments that are currently need. The code is added by using the JavaScript eval function. Is something like this still possible in the ms-wwa context? If yes how compare it to scripts loaded by a script tag from a file from the app file container? Do they get the same level of optimization? If eval is not on option would adding them as script tag to the DOM an alternative? I am talking about script tags that include the source directly instead of refer to a file. Because if I have understand it right loading script inside the ms-wwa context is only allowed from the app container that is signed.

    Saturday, September 17, 2011 9:56 AM

Answers

  • Hi Ralf,

    Funny you should mention fragments... Fragments are how we are able to keep state in WWA applications in the default templates. I think you would benefit from an overview of this to understand how jscript and HTML is managed in the template projects and how you may be able to leverage this in your application.

    If you create a Javascript application from the Split Template you can see this in action.

    When you open the default.html file you will see the script references as you would expect in any HTML file. Now open splitPage.html. You will see the deferred keyword:

    <script type="ms-deferred/javascript" src="/winjs/js/base.js"></script>

    This will ensure the file references will be entered into the namespace once and only once! What this also means however is jscript you include will stay in memory.

    Similarly the default.js code queues and event: queueEvent({ type: 'fragmentappended'

    When the navigate function is called (put a bp on that function to see this) this calls the fragmentLoad function of this page and loads only the parts of the HTML necessary to build the page... roughly this means it throws away the HTML and Script that is not necessary.

    All this said, you can easily only include jscript on the views that you define that require that jscript and it will be included once and only once if you follow this pattern of programming you do not need to use eval at all. You can use eval still but I would recommend leveraging the model that I briefly outlined above.

    Does that help you?


    Jeff Sanders (MSFT)
    Monday, September 19, 2011 8:07 PM
    Moderator