How to ensure that WinJS.xhr resends requests (HTML)

[ This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation ]

When you request Web resources by using WinJS.xhr, the response might be cached, which means that later requests will return the version of the resource that already exists on the client computer rather than resending the request. However, you can add an HTTP header that ensures that the request is sent again, even if it has already been cached.

Prerequisites

Instructions

Step 1: Ensuring that the client resends requests

This code shows how to set the If-Modified-Since HTTP header, which specifies that the client should resend the request to check for a more recent version of the resource.

  • Add the If-Modified-Since header to the headers property of the options parameter to the WinJS.xhr function. For more information about HTTP response headers, see HTTP Response Headers.

    WinJS.xhr({ 
        url: "https://www.microsoft.com",
        headers: {
            "If-Modified-Since": "Mon, 27 Mar 1972 00:00:00 GMT"
        } })
        .done(function complete(result) {
            // Report download.
            xhrDiv.innerText = "Downloaded the page";
            xhrDiv.style.backgroundColor = "#00FF00";
    });
    

Other resources

Connecting to web services

How to download a file with WinJS xhr

Reference

HTTP Response Headers

WinJS.xhr

XMLHttpRequest

XMLHttpRequest enhancements

Samples

Integrating content and controls from web services sample

Using a Blob to save and load content sample

Web authentication sample

XHR, handling navigation errors, and URL schemes sample