css & js files don't unload on navigation RRS feed

  • Question

  • I noticed that if I am on pag1 and load page1.css & page1.js then navigate to page2 that the page1 css and js files are still loaded and apply to the DOM....

    Is that by design?  Why?  How do I prevent it from happening?


    Thursday, July 12, 2012 11:27 AM


All replies

  • Yes it is by design.  Why do you want to prevent this?

    Jeff Sanders (MSFT)

    Thursday, July 12, 2012 1:47 PM
  • how is this a good design decision?  I am just curious.  If I am on page2, I don't want page1 stuff...  that causes all kind of js and css conflicts...  I can work around it but I really prefer to "unload" stuff I am not using - is there a way to do that?


    Thursday, July 12, 2012 7:04 PM
  • HI

    A traditional website might have a series of pages that you navigate between using hyperlinks. Each page has its own set of JavaScript functions and data, a new set of HTML to display, style info, and so on. This navigation model is known as multi-page navigation.

    Unlike a traditional website, a Metro style app using JavaScript works best when it uses  the single-page navigation model. In this model, you use a single page for our app and load additional data into that page as needed.

    Because your app's main page is never unloaded, your scripts are never unloaded, which makes it easier to manage activation, state,  and animations. When users run your app, they experience a smooth, application-like experience that doesn't have to  pause to load new pages  and doesn't ever display blank screens. We recommend that  Metro style apps using JavaScript use the single-page navigation model.

    Friday, August 3, 2012 7:06 AM
  • Hi Emad,

    Think of your WinJS app as a traditional application.

    For instance the Grid view which has Multiple pages.  If you had to bring into memory the page you had and reconstruct it from disk every time it would be very inefficient.  Remember, unlike the browser... WinJS apps are predefined, you cannot randomly load js and html into your application.  You do not have to worry about js conflicts since you are using the anonymous function to wrap everything in your page.js file right (if you are not, you should)?  You should not have CSS conflicts because your app should look and feel the same as you navigate through it.  If you have to define different CSS for a particular page you can easily do it in that page CSS and give it an appropriate class name.  Yes this is very different from a Website model, and it should be.  It may take you some time to wrap your head around this.  Thanks for the questions!


    Jeff Sanders (MSFT)

    Friday, August 3, 2012 11:58 AM
  • So if I want, is there a way to unload pages .css script on Unload event?

    Thursday, January 31, 2013 1:29 PM
  • No there is not.


    Jeff Sanders (MSFT)

    Thursday, January 31, 2013 8:52 PM