getUrl( resourceUrl, [policy] ) method

Creates a media cache URL for the resource.

The cache first policy will be used if no policy is specified.

Syntax

<static> getUrl( resourceUrl, [policy] ) → {string}

Parameters

Name Type Argument Description
resourceUrl string   The URL to the resource
policy hwc.MediaCache.Policy (optional) The optional cache policy to use.If set, it must be either hwc.MediaCache.Policy.SERVER_FIRST or hwc.MediaCache.Policy.CACHE_FIRST. Default policy is cache first.

Returns

The URL that can be used to access the resource with the specified caching policy.

Type:

string

Example

// This line creates a url that can be used to retrieve the picture from the cache if possible, and from the server otherwise.
var mediaCacheURL = hwc.MediaCache.getUrl( "http://yourserver.com/Pictures/pentagon.jpg", hwc.MediaCache.Policy.CACHE_FIRST );
// The following function adds a picture to the page. Since the mediaCacheURL variable is used for the url, the picure will be
// retrieved from the cache if possible.
var addPicFromMediaCache = function()
{
   // Create the image element.
   var image = document.createElement( "img" );
   // Set the source of the image to the media cache URL.
   image.setAttribute( 'src', mediaCacheURL );
   // Add the image element to the page.
   document.body.appendChild( image );
}
// This line creates a url that can be used to retrieve the picture from the server if it is available, or the cache otherwise.
var mediaCacheURL_serverFirst = hwc.MediaCache.getUrl( "http://yourserver.com/Pictures/pentagon.jpg", hwc.MediaCache.Policy.SERVER_FIRST );
// The following function adds a picture to the page.  Since the mediaCacheURL_serverFirst variable is used for the url, the picture will be gotten
// from the server if the server is available, and from the cache otherwise.
var addPicFromMediaCache_ServerFirst = function()
{
   // Create the image element.
   var image = document.createElement( "img" );
   // Set the source of the image to the media cache URL.
   image.setAttribute( 'src', mediaCacheURL_serverFirst );
   // Add the image element to the page.
   document.body.appendChild( image );
}

Source

hwc-api.js, line 3442.