Disabling the Browser Cache

Tutorial by Chris Hunt – nospam@cwhunt.com

in collaboration with Ron Broglio – ron.broglio@gatech.edu

 

1. Purpose

This patch for enCore disables the storage (caching) of dynamic data in the player’s web browser.

Browsers store copies of pages on the user’s computer for faster access. Sometimes this causes them to display erroneous content. This is why an object or player may not appear after a “look” command, even if the player knows that they have just entered the room.

 

2. Background

The contents of any room in MOO space are dynamic: players enter or exit and interact with objects—sometimes taking them into or out of their inventory. Advanced MOOs are even more dynamic: room names, icons, descriptions, and contents vary according to the state of the system. Is the player following a narrative or wearing a costume? Does the room determine its appearance according to certain events? All of these things require up-to-date content in the Xpress window.

            Web browsers save, or “cache”, recently viewed pages onto the user’s computer. When the user requests that page again, the browser displays the local copy. This is an effective way of increasing browsing speed across pages with static content. However, MOO pages are dynamic and local copies often have obsolete information.

It is easy to disable caching on a per page basis. A simple tag is inserted near the top of each HTML document—preferably in the <HEAD> block, although it may be inserted anywhere:

 

<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>

 

However, enCore generates its HTML dynamically. We have to change the way it builds pages. This can be done two ways:

 

·        Disabling the cache for all HTML pages in the MOO (Wizard level)

·        Disabling the cache for each object, room, or player (Programmer level)

 

I strongly recommend the first solution if you have the security privileges. Every HTML page in the MOO suffers from this update problem, and very few pages in any MOO are large enough and static enough for useful caching.

 

3. Implementation

 

3.1 System-wide

Changing the system-wide behavior is actually easier than changing it per room, but the change is far more delicate. A programming mistake for one room will not affect the entire MOO; an incorrect edit in the generic enCore Web Object is much more serious. Incorrectly editing this verb could prevent enCore from displaying any web pages!

 

That being said, the fix is very easy. Open the Program Editor. Type “$enCore_web_object” into the box at the top left corner and press “View” (do not include the quotes). This should display the page for the enCore Web Object in your MOO. Examine the verb list and find “_html”. This is a long and complicated verb. I recommend saving the contents to a file for backup. Scroll to the bottom.

 

Insert a line break between “endif” and “return html;”

 

Figure 3.1.1

 

Insert this line:

 

html = {"<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>", @html};

 

Your window should now look like this:

 

Figure 3.1.2

 

Press “Compile Verb”. You should not receive any errors.

 

Simply delete this line to re-engage the browser cache.

 

3.2 Per Room Implementation

Open the Program Editor on your room. Create a new verb called “_html”. Its permissions for “read” and “execute” should be activated. Its arguments list should read “this, none, this”.  Paste the following code in the large blank box:

 

“This method inserts a no-cache tag into the encore html for this room. That is why changes are noticed immediately.";

noCache_header = "<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>";

return {noCache_header, @pass(@args)};

"Code and tutorial by Chris Hunt -- nospam@cwhunt.com";

"Maintained and published by Dr. Ron Broglio, Georgia Tech";

" ron.broglio@lcc.gatech.edu";

 

Your Editor should look like this:

 

Figure 3.2.1

 

Press the “Compile Verb” button. It should briefly clear the screen and report in the bottom, right hand corner: “0 errors. Verb Programmed.”

 

You can check if the pages are being cached by viewing their source and looking for our tag:

 

<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>

 

It should be at the beginning of the <BODY>.