Thursday, May 12, 2011

HTML in AIR: Part 2

Today we will learn about controlling caching of the content, controlling authentication and setting user agent for a HTMLLoader object in AIR.

HTMLLoader has some properties that influence the display of the HTML content in your AIR application. In this tutorial, we'll learn about a few of them. Note, that all of them shall be applied to the HTMLLoader object before the load() method is called.

The first thing we need to know about is caching. If you don't know what caching is - it is basically the process when browsers loads web-page content when you first open the page in the internet and saves this content locally, so that the next time you visit this site - the pages will be loaded from your local storage.

This saves loading time, but sometimes caching might not be a good thing. For example, some content on the web-page that is cached on your machine might be updated and you won't see the updates, because you're loading the old data from your local storage. The cached files are stored there until the user manually removes them, or they reach their expiration date.

You can prevent unwanted caching, and there are 2 ways to do that: the first one is to tell AIR not to cache the data, and the second is to tell AIR not to read the cached data and just load the page from the internet.

If you want to tell AIR not to cache the page, you can set the cacheResponse property of it to false.

myHtml.cacheResponse = false;

If you want to tell AIR not to read from cache, you can use its useCache property.

myHtml.useCache = false;

The next thing is authentication. You might have encountered some pages on the internet that require you to enter a user login and password to see the content (this is done by having .htaccess files on the server, which limit the users' access to the content). When that happens, a new window pops up and asks you to enter your ID and password.

If you want to turn this behaviour off, you can set the authenticate property of your HTMLLoader object to false, and the window will not pop up (the server will return an error this way).

myHtml.authenticate = false;

Finally, the user agents. A user agent is the application that asks the server to give it the content. Some server scripts have it that the content is displayed differently for certain user agents, or nothing is displayed at all.

This is why sometimes user agent spoofing takes place. This basically means that sometimes people fake their user agents, by setting their values to look like their user agent is another browser program. You can do that by applying a string value to the userAgent property of the HTMLLoader object. You can learn more about the user agents on the Wikipedia page.

myHtml.userAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";

That's all for now. Remember to use all these properties before you call the load() method.

Thanks for reading!

Related:

HTML in AIR: Part 1
HTML in AIR: Part 3
HTML in AIR: Part 4
HTML in AIR: Part 5
HTML in AIR: Part 6
HTML in AIR: Part 7
HTML in AIR: Part 8
HTML in AIR: Part 9
HTML in AIR: Part 10
HTML in AIR: Part 11
HTML in AIR: Part 12
HTML in AIR: Part 13
HTML in AIR: Part 14
HTML in AIR: Part 15
HTML in AIR: Part 16
HTML in AIR: Part 17

No comments:

Post a Comment