Refresh .WML card
Написал Ярослав Гасов   
08.08.2008

Share this!

Those of you who have some experience from the "web" environment will most likely have used the meta http-equiv="refresh" tag to force a browser to load a new or the same page.

 

Although some META tags are supported in the WAP environment, a much better way of doing the exact same thing in WML is to use the <ontimer> tag:

 

The following piece of code will force the browser to load another deck after a certain time. For the example below, the deck will jump to another deck called nextdeck.wml:

 

  <?xml version="1.0"?>
  <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
  <wml>
    <card id="splashscreen" ontimer="nextcard.wml">
      <timer value="40"/>
      <p>Please wait for the timer to run out...</p>
    </card>
  </wml>

The following piece of code will force the browser to reload the same card after a certain time. For the example below, the deck file is called loop.wml:

 

  <?xml version="1.0"?>
  <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
  <wml>
    <card id="loop" ontimer="loop.wml">
      <timer value="40"/>
      <p>This text will be shown over and over again...</p>
    </card>
  </wml>

Note that for a browser to actually reload the same card, you will need to bypass the browser's caching mechanism, or else the card will be loaded from the browser's memory, and not from the server.

 

After a WML deck has been downloaded to the WAP device, it lives in the WAP device's memory for a certain period of time. Until this period has expired, the deck will not be downloaded from the server but instead from the WAP device memory. This is known as caching, and it obviously speeds things up considerably.

 

The following PHP example produces the above header each time the deck is accessed:

 

<?
  header("Content-type: text/vnd.wap.wml"); 
  header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 

  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 

  header("Cache-Control: no-cache, must-revalidate");  

  header("Pragma: no-cache");

?>

 

The following deck will always be loaded off the server. Note that you should never use this unless you know what you're doing since it eats bandwidth and "wastes" time, every time the deck is requested:

 

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
  <head>
    <meta forua="true" http-equiv="Cache-Control" content="max-age=0"/>
  </head>
  <card id="alwaysexpire">
    <p>This deck will never be stored in the cache</p>
  </card>
</wml>

 

Some browsers such as the UP.Browser will not reload a deck if it is reached by going "back" from another card. (The object of the cache is to save bandwidth and time). To force this behaviour, you must use the must-revalidate parameter to the META tag:

 

<meta forua="true" http-equiv="Cache-Control" content="must-revalidate"/>

Последнее обновление ( 08.08.2008 )