共用方式為


Prefetch content for Windows Store apps

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Applies to Windows only](../Image/windows_only_content.png "windows_only_content")

To make your Windows Store app more responsive, you can request Windows to preload some web content, such as web pages or images, into the app's WinINetWinINetcache. This functionality is called prefetching. It’s especially effective for content that's used at startup but you can prefetch other frequently used content, too. The methods of the Windows.Networking.BackgroundTransfer.ContentPrefetcher class let you specify the URIs of the content that you want to preload.

Windows uses heuristics to determine when and if prefetching should occur and which resources will be downloaded. The heuristics take into account system network and power conditions, user app usage history, and the results of prior prefetch attempts. In Visual Studio, you can use the Trigger Windows Store App Prefetch command to force Windows to ignore the ContentPrefetcher heuristics and preload all of the specified web content. This can be useful if you want test the app's behavior or performance with the content to prefetch in a known state (either loaded or not loaded).

To force preloading of ContentPrefetcher specified resources

This procedure assumes that you have already set up the ContentPrefetcher functionality and specified the content URIs to preload in your app project. To force a preloading of content when the specified resources are new or modified, you have to start and stop the app before you choose the Trigger Windows Store App Prefetch command. You run the app first to register the URIs. Trigger Windows Store App Prefetch command then forces the ContentPrefetcher to download the content and add it the cache. In subsequent runs of the app, you can assume that the content is preloaded.

  1. Start the app to register the prefetch content URIs with the app. On the Debug menu, choose Start Debugging (Keyboard shortcut: F5).

  2. On the Debug menu, choose Stop Debugging (Keyboard shortcut: Shift + F5).

  3. On the Debug menu, choose Other Debug Targets and then choose Trigger Windows Store App Prefetch.

    You can now debug, test, or analyze your app with the prefetched web resources.

Note

Repeat these steps whenever you add or modify the specified web content.

See Also

Blog post: Triggering Prefetch for Windows Store Apps in Visual Studio 2013 Update 2