23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5. document.DOMContentLoaded fires. You can use this to do further initialization specifically related<br />

to the DOM, if desired (not common).<br />

6. Windows.UI.WebUI.WebUIApplication.onactivated fires. This is typically where you’ll do all<br />

your startup work, instantiate WinJS and custom controls, initialize state, and so on.<br />

7. The splash screen is hidden once the activated event handler returns (unless the app has<br />

requested a deferral as discussed later in the “Activation Deferrals” section).<br />

8. body.onload fires. This is typically not used in Windows Store apps, though it might be utilized<br />

by imported code or third party libraries.<br />

What’s also very different is that an app can again be activated for many different purposes, such as<br />

contracts and associations, even while it’s already running. As we’ll see in later chapters, the specific<br />

page that gets loaded (step 3) can vary by contract, and if a particular page is already running it will<br />

receive only the Windows.UI.WebUI.WebUIApplication.onactivated event and not the others.<br />

For the time being, though, let’s concentrate on how we work with this core launch process, and<br />

because you’ll generally do your initialization work within the activated event, let’s examine that<br />

structure more closely.<br />

Sidebar: File Encoding for Best Startup Performance<br />

To optimize bytecode generation when parsing <strong>HTML</strong>, <strong>CSS</strong>, and JavaScript, the Windows Store<br />

requires that all .html, .css, and .js files are saved with Unicode UTF-8 encoding. This is the default<br />

for all files created in Visual Studio or Blend. If you’re importing assets from other sources, check<br />

this encoding: in Visual Studio’s File Save As dialog (Blend doesn’t have this at present), select<br />

Save with Encoding and set that to Unicode (UTF-8 with signature) – Codepage 65001. The<br />

Windows App Certification Kit will issue warnings if it encounters files without this encoding.<br />

Along these same lines, minification of JavaScript isn’t particularly important for Windows<br />

Store apps. Because an app package is downloaded from the Windows Store as a unit and often<br />

contains other assets that are much larger than your code files, minification won’t make much<br />

difference there. Once the package is installed, bytecode generation means that the package’s<br />

JavaScript has already been processed and optimized, so minification won’t have any additional<br />

performance impact.<br />

102

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!