Question

I am using the TWebBrowser component with Delphi 7. With the TWebBrowser I am retrieving my own HTML files placed on my server. I do not want copies of the HTML files to be easily found by the user. Currently, all of the files retrieved via the internet through the TWebBrowser are getting stored in the Temporary files folder as configured via Microsoft's Internet Explorer > Tools settings. I do not like this, for it doesn't take a rocket scientist to look there for copies of the downloaded files.

I was surprised that despite the fact that my HTML files have the following lines in the <HEAD></HEAD> section, the files are still being stored in the Temporary files folder:

<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="-1" />

I do notice that if the HTML file is local, that is, outside the Temporary files folder and not retrieved via the internet, IE/TWebBrowser does NOT stash a copy in the Temporary files folder.

I guess what I am asking is, am I doing something wrong with my META tags, or do these tags have no affect upon how the TWebBrowser handles files retrieved remotely?

Any solutions, besides having to use an INDY HTTP component to fetch the files instead, then loading them from a hidden folder on the user's drive?

Was it helpful?

Solution

Telling a browser not to cache, such as with the Cache-Control: no-cache directive, simply tells it not to reuse the cached data on subsequent requests, but instead, it must re-request the data from the server each time. It says nothing about caching the file locally for off-line browsing, etc.

By the way, I prefer to use the Cache-Control: no-cache HTTP header rather than specify this in a meta tag because the HTTP header is recognized by and passed through proxies and other caching mechanisms between the server and the browser.

Instead, take a look at the Cache-Control: no-store and private directives, which tells the web browser and any shared caching mechanisms, such as proxies, not to store the data.

Note, however, that you can help protect the user's data, but you can't protect them from themselves. There are registry settings that allow a user to override the "no-store" directive in IE.

Perhaps an in-memory solution would be better.

OTHER TIPS

I can't comment as to why the <meta> are not taking effect. But I can say that the TWebBrowser.Navigate() and TWebBrowser.Navigate2() methods both have a Flags parameter. You can specify the navNoWriteToCache flag to prevent the retrieved data from being saved to the cache.

Supply NavNoReadFromCache to the Navigate method as the second parameter.

procedure TForm1.Button1Click(Sender: TObject);
var
  Flags: OLEVariant;

begin
  Flags:=4; //NavNoReadFromCache
  WebBrowser1.Navigate('http://www.example.com', Flags);
end;

Browser.EnableCaching:=False; Browser.Navigate;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top