What is the best way to ensure that the contents of a web page are downloaded from your website instead of using cached temporary internet files?

I noticed that when updating web content files (in this case, the Xlight Silverlight file), the browser does not detect that the file is updated and continues to read the locally cached file. These files will rarely update, so reading from cached temporary Internet files should happen in most cases.

My question is, is there a programmatic way to ensure that files are downloaded from a website, and not read from the local cache, but only when these files have changed? Is there a widespread process for handling this scenario? I do not want every user of this web product to have to delete their temporary Internet files when installing the update.

These files will only be updated during the installer, so can I programmatically install something to make this happen?

+4
source share
4 answers

A lot of software solutions. However, the solution is to simply configure ClientBin server code on the server (or any other folder in which your XAPs are stored).

Assuming IIS needs to explicitly specify the ClientBin folder, it expires immediately. This will send the correct cache configuration headers when receiving XAP. In turn, the browser will try to remove XAP every time it is needed, but in the vast majority of cases it will simply receive a 304 Unmodified response and can continue to use its cached copy.

I assume that you are seeing the classic IE heuristic problem. In the absence of any caching configuration headers, IE decides on its own whether to even re-request the resource in accordance with its own internal algorithms. By ensuring that the correct expiration headers are sent, IE will follow the server instructions.

Edit

It seems I need to make the work of this approach clearer. This approach does not leave the XAP resource inactive and needs to be retrieved whenever necessary.

By specifying the Expire Immediately function in IIS, we get these headers in response: -

HTTP/1.1 200 OK Cache-Control: no-cache Content-Length: 22359 Content-Type: application/octet-stream Last-Modified: Tue, 21 Jul 2009 11:59:28 GMT ETag: "fe734cb3fa9ca1:1352" 

This does not interfere with XAP caching, it simply indicates that the browser cannot use cached XAP without first requesting from the server. Check out the Last-Modified and ETag headers.

The following query looks like this: -

 GET /clientBin/SomeApp.xap HTTP/1.1 If-Modified-Since: Tue, 21 Jul 2009 11:59:28 GMT If-None-Match: "fe734cb3fa9ca1:135a" Host: myhost.com 

Answer: -

 HTTP/1.1 304 Not Modified Cache-Control: no-cache Last-Modified: Tue, 21 Jul 2009 11:59:28 GMT Tag: "fe734cb3fa9ca1:135a" 

This answer has no entity body; it gives the browser permission to go ahead and use the existing XAP in the cache.

If the XAP is large, then it is possible that the browser is not actually caching it using Cache-Control, specified as no-cache. Therefore, it may be better to be more explicit.

Instead of using the Expire Immediately field, configure the Cache-Control header using the Custom Header List. Indicate: -

 Cache-Control: max-age=0 

This will cause the browser to cache large XAP files while expiring them.

+1
source

You can add a random number or datetime value to the query.

The problem occurs most often when an AJAX call is made. To avoid getting values โ€‹โ€‹from the cache, you can create a query.

For instance:

 var xmlPath = "www.domain.com?vers="+new Date().getTime();+""; 
+2
source

Your question is a bit vague as I don't know what tools you use. I will give examples in PHP.

You want to set the Cache-Control header to indicate the maximum age that the file can cache. The value is in seconds.

eg.

 <?php header("Cache-Control","max-age=86400"); 

You must set this header before sending the XAP file to the user. 86400 seconds = 1 day.

Another alternative is to use different file names for each version of the file. You can do this in one of two ways.

Insert version # in the file name:

 some_file_1_1.xap some_file_1_2.xap 

Or, my preference is to add the version number to the file name as a query string:

 some_file.xap?20090719 some_file.xap?20090720 

You would refer to these files with the corresponding "version" number in your HTML code, and when changing the browser version, the browser takes into account the change in the file name and forces it to reload. You can use whatever you want for the version string - parameters may include: revision #, last modified date, etc.

If you decide to go with a file name change in each revision, I would suggest using caching for the โ€œdistant futureโ€. Providing file caching for an insanely long time will reduce the load on your server. You can do this as shown above with PHP, and here are some examples to do this with mod_expires in Apache 2.0.

 ExpiresActive on ExpiresByType application/x-silverlight-app "access plus 5 years" FileETag none 
0
source

I think you can do something like this: obviously, do it in the base class that each page will use. So create like PageBase, which inherits from System.Web.UI.Page and has all its code behind inherited from PageBase.

or do it on the main page.

 protected void Page_Init(object sender, EventArgs e) { Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetNoStore(); } 
0
source

All Articles