Relay scripts and image caching

Bale

Minion
I recently learned something new about KoLmafia's functionality and I cannot figure out for myself if it is a bug or intended behavior. When a relay script uses an image from http://images.kingdomofloathing.com/ the actual image from that URL is used, bypassing the cached image entirely.

This seems that it might be a violation of KoLmafia's desire to use its own image cache instead of hitting KoL's server every time the image is required. This seems particularly noticeable since KoLmafia has recently upgraded its image caching features and made their use mandatory. On the other hand, perhaps there is some value to this behavior that I am simply overlooking. I am hoping someone can enlighten me.

Bug or feature?
 

Veracity

Developer
Staff member
When KoLmafia gets a page from KoL, it decorates it before passing it back to the browser. One of the things it does is change http://images.kingdomofloathing.com/xxx to /images/xxx. This makes the Browser request the image from KoLmafia's cache. If it is not there, KoLmafia fetches it, and subsequently, it is found locally.

I believe that KoLmafia also decorates the page that it fetches from KoL before passing it to a Relay Script, which has a further chance to modify it to its own taste. It does NOT decorate the page AFTER the Relay script has finished its work. So, if the relay script puts in a link to images.kingdomofloathing.com, that gets passed to the browser untouched.

Now that image caching is mandatory, relay scripts should ask for such images using /images/xxx, just as if KoLmafia had munged the link, to make allow KoLmafia's caching to work as expected.
 

Veracity

Developer
Staff member
Note that we could change this to munge images.kingdomofloathing.com into /images as the last step before we send the page down to the browser. I.e. AFTER the relay script has done its thing.

That might be the correct thing to do, since it will force image caching whether or not the script takes advantage of it.
 

Veracity

Developer
Staff member
OK, Revision 12896 munges images.kingdomofloathing.com to /images as the very last thing before the responseText is turned into a raw byte buffer and handed down to the browser, rather than doing it as part of normal web page decoration, which happens before giving the page to relay scripts.

Relay scripts can reference either images.kingdomofloathing.com - which we will munge into /images - or /images - which we will not, since it is already munged - thereby taking advantage of image caching with no special effort.
 

Bale

Minion
Thank you. This came up in ChIT where someone wanted to alter images in cache and have them appear that way in the charpane, but since ChIT was referencing KoL's image server, he was seeing the unaltered images. I altered ChIT to reference the /images directory so it would work that way, but I was still concerned if mafia was behaving properly. And concerned that other relay scripts should allow that as well.


Munge is a sweet word, and I need to use it more often in a professional capacity.

Because it sounds naughty when you use it in an unprofessional capacity?
 
Top