1

I have some code that generates a new KMZ file every 24 hours (each tour has many points and takes about 18 hours to complete). And I have a webpage with the Google Earth plugin which automatically loads and runs the tour (called latest.kmz).

Now I'm trying to set up an unmanned computer in the lobby with the browser (Chrome) pointing to my website. Every morning, e.g. at 8am I want the webpage to refresh and start the new tour.

Unfortunately, even though I overwrite the latest.kmz during the night, when the page refreshes (using http://...etc...">) it still continues to use the cached version of latest.kmz.

How can I force it to reload the latest version of the kmz from disk?

andyabel
  • 335
  • 4
  • 15

2 Answers2

0

Force cache no-validation using content headers if you are not doing so already. This can be achieved by firing your KMZ file with the following header:

Cache-Control: max-age=0, must-revalidate

This will force the useragent to consider the file stale immediately, which means that on the next request, it will not use its cache. Check your current headers just in case, as you may have something in that header already - and adjust accordingly.

Sébastien Renauld
  • 19,203
  • 2
  • 46
  • 66
0

Two ways, you can simply append a time-stamp or random query string to the KMZ request url. This essentially makes each request for the data unique thus avoiding any caching issues.

For example, you could create the url to your KMZ and append a UNIX timestamp like so.

var kmz = "http://localhost/your.kmz?x=" + (new Date()).getTime();

Producing unique results like this.

http://localhost/your.kmz?x=1365635454757
http://localhost/your.kmz?x=1365635478881

The other way would be to load your KMZ file using networklinks (if you aren't doing so already) this way you can control exactly when to check for new data again avoiding caching issues. This way the page doesn't need to refresh at all - a simple network link in a kml file that points to your data would work by setting the refresh interval to the number of seconds until the file is reloaded.

Something like.

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
    <NetworkLink>
    <name>your file</name>
    <flyToView>1</flyToView>
    <Link>
      <href>http://localhost/your.kmz</href>
      <refreshMode>onInterval</refreshMode>
      <refreshInterval>86400</refreshInterval><!-- 24 hours -->
    </Link>
  </NetworkLink>
</kml>
Fraser
  • 15,275
  • 8
  • 53
  • 104