Suggestions for the comic script

Talk about today's strip, or anything about the comic in general. You can also talk about any of the characters... but don't expect a response. They're FICTIONAL, you guys... sheesh. :)
Noxious Ninja
Redshirt
Posts: 10
Joined: Fri Oct 29, 2004 4:33 am
Contact:

Suggestions for the comic script

Post by Noxious Ninja » Fri Oct 29, 2004 4:58 pm

I have a couple of suggestions for the comic script. I.e., index.php?do_command=show_strip

One of them fixes an annoyance with Firefox and may save some bandwidth, the other two are a bit of polish.

1) Enable proper client-side caching by making the script support HTTP conditional GET.

First off, you must send a Last-Modified header with each image. This can be done with something like

Code: Select all

$lastmodstring = gmdate ('D, d M Y H:i:s \G\M\T', filemtime ($imagefile));
header ('Last-Modified: ' . $lastmodstring);
Next, send an Etag header. This can be pretty much anything, so long as it is unique to each file. I personally use an MD5 hash.

Code: Select all

$etagvalue = '"' . md5_file ($imagefile) . '"';
header ('Etag: ' . $etagvalue);
Now, when the browser requests the image again, it will send an If-Modified-Since header and an If-None-Match header. You can check this against the last-mod date and etag, respectively, and, if they match, send back an HTTP 304 header and cease output.

Code: Select all

$headers = getallheaders();

if (isset ($headers["If-Modified-Since"])) {
   if (isset ($headers["If-None-Match"]) {
      if ($headers["If-Modified-Since"] == $lastmodstring) {
         if ($headers["If-None-Match"] == $etagvalue) {
            header ('HTTP/1.1 304 Not Modified');
            ob_end_clean ();
            exit ();
         }
      }
   }
}
Benefit: The comic will not have to be retransfered every single time it is requested. For example, if I check the site, and a new comic hasn't been put up yet, I will get the cached version. Or, if a strip refers to something from a few days ago, and I go back to that strip to check it out, it won't have to reload.

Note: IE seems to have some funky aggresive caching, and doesn't rely on this, but it makes Firefox (and me) happy.

For more info on HTTP Conditional GET, see here.


2) Send a filename for the file. Something like strip_id_YYYY-MM-DD

Code: Select all

header ('Content-Disposition:inline; filename="1310_2004-10-29.png"');
Benefit: When I right-click on an image to save it, I don't have to spend a moment figuring out what the proper name is. Plus, the filename contains the date the comic was published, so I can get a quick idea of how far apart things were.


3) Send a file length

Code: Select all

$image = file_get_contents ('$imagefile');
header ('Content-Length: ' . strlen ($image));
Benefit: Um, not much, actually. It's just easy to do, and makes the script a bit more complete. Oh, and it gives you good "leet haxxor" karma.


Barring any typos, the above should be correct. I hope you find it useful.

Cheers, and thanks for the great comic.
Last edited by Noxious Ninja on Fri Oct 29, 2004 9:06 pm, edited 2 times in total.

User avatar
Mae Dean
Forum Goddess
Forum Goddess
Posts: 4450
Joined: Tue Feb 11, 2003 7:10 pm
Location: San Francisco, CA
Contact:

Post by Mae Dean » Fri Oct 29, 2004 6:09 pm

I will forward this on to Ukyo... perhaps he'll see fit to implement these changes. We'll see. ^^

User avatar
Focus
Redshirt
Posts: 124
Joined: Thu Feb 20, 2003 7:12 pm
Location: Minnesota
Contact:

Post by Focus » Fri Oct 29, 2004 6:58 pm

Whew.... I was afraid was going to be another "Greg should wear lampshades on his feet because I think it would be a funny comic" type of suggestion. I was thinking of a different type of script. :wink:

Noxious Ninja
Redshirt
Posts: 10
Joined: Fri Oct 29, 2004 4:33 am
Contact:

Post by Noxious Ninja » Fri Oct 29, 2004 9:08 pm

[quote="Greg Dean";p="416188"]I will forward this on to Ukyo... perhaps he'll see fit to implement these changes. We'll see. ^^[/quote]

Cool.

BTW, I fixed a couple of typos in the above.

User avatar
billf
Pantless power
Pantless power
Posts: 7052
Joined: Tue Feb 11, 2003 8:27 pm
Location: New York... The part with the cows
Contact:

Post by billf » Fri Oct 29, 2004 10:46 pm

[quote="Focus";p="416201"]Whew.... I was afraid was going to be another "Greg should wear lampshades on his feet because I think it would be a funny comic" type of suggestion. I was thinking of a different type of script. :wink:[/quote]

I was thinking the same thing.
Image
"We spend the first year of their lives teaching them (children) to walk and talk, and the rest of their lives telling them to shut up and sit down."

User avatar
Killer-Rabbit
Redshirt
Posts: 2395
Joined: Fri Feb 14, 2003 2:46 pm
Gender: Male
Location: Traverse City, Michigan

Post by Killer-Rabbit » Fri Oct 29, 2004 11:46 pm

Same. The words are too similar. I leave it to you billf to come up with new names that no one can mix up.

dmpotter
Redshirt
Posts: 4057
Joined: Tue Apr 01, 2003 7:10 pm
Location: Massachusetts, US
Contact:

Post by dmpotter » Sat Oct 30, 2004 12:03 am

s/script/web site/

That's my suggestion. Well, it's in PHP, so I guess

Code: Select all

$thread_title = preg_replace("/script/", "web site", $thread_title);
is better.

User avatar
CyberEd
Redshirt
Posts: 1786
Joined: Tue Sep 21, 2004 2:48 am
Location: Israel
Contact:

Post by CyberEd » Sat Oct 30, 2004 12:30 am

/me was thinking in the same lines as these other people...
welcome to the forum btw
Image

User avatar
BtEO
Redshirt
Posts: 4803
Joined: Tue Feb 18, 2003 2:28 pm
Location: England
Contact:

Post by BtEO » Sat Oct 30, 2004 12:56 am

While that would do fine dmpotter, might I suggest practising a slightly more polished form of regexps in future.
Script should probably have been bounded by \b to make sure "scripting" doesn't become "web siteing".
Also this one probably should be a case-insensitive search, so an "i" mode modifer would be needed, as would a "g" replace all occurances modifier in the first syntax (preg_replace() does that as default though).
To sum up

Code: Select all

s/\bscript\b/web site/ig
and

Code: Select all

$thread_title = preg_replace("/\bscript\b/i", "web site", $thread_title);
You should always match as tightly as possible even when you "know" you don't really need it, that way there's less risk of getting screwed later by making foolish assumptions. :P
And to think, at first I hated regexps.

WCH
Redshirt
Posts: 103
Joined: Tue May 25, 2004 3:18 am

Post by WCH » Sat Oct 30, 2004 5:44 pm

Heh, yeah... I saw the name of the thread and immediately thought "Hoo boy, here we go... someone's getting flamed..."

User avatar
Mr.Shroom
Redshirt
Posts: 2522
Joined: Fri Apr 18, 2003 8:44 am
Location: Secret Underground Lair

This is probably a sign of the end-times.

Post by Mr.Shroom » Sat Oct 30, 2004 9:32 pm

Wow. A thread actually worth Greg's time. Whodda thunk it?

User avatar
Rembrandt Q. Einstein
Redshirt
Posts: 1419
Joined: Fri Sep 12, 2003 2:29 pm
Location: University of Connecticut, Storrs, CT

Post by Rembrandt Q. Einstein » Sat Oct 30, 2004 9:46 pm

not only that, but a suggestion for the comic thread that's actually worth Greg's time. You're going places newbie.
"GREASE ME WITH LARD AND GLUE MY ASS CLOSED I'M HEADING FOR THE HILLS!" -Mandor
"That is democracy, even if what you say doesn't move heaven and earth it is still absolutely vital that it be said." -randomperson2

Noxious Ninja
Redshirt
Posts: 10
Joined: Fri Oct 29, 2004 4:33 am
Contact:

Re: Suggestions for the comic script

Post by Noxious Ninja » Tue Nov 30, 2004 5:48 pm

Well?

OniNeko
Redshirt
Posts: 1960
Joined: Tue Oct 07, 2003 3:13 pm
Location: Salt Lake City, UT
Contact:

Post by OniNeko » Tue Nov 30, 2004 5:56 pm

Purple Tallest: You got your sandwhich.
Me: You got your necro.
"... to see with eyes unclouded by hate."

User avatar
Deacon
Shining Adonis
Posts: 44234
Joined: Wed Jul 30, 2003 3:00 pm
Gender: Male
Location: Lakehills, TX

Post by Deacon » Tue Nov 30, 2004 6:40 pm

Comic script improvements can help, certainly, but does anyone know why RL always loads so slowly? It's like traffic is being crammed through a highly restrictive paketeer or something...
The follies which a man regrets the most in his life are those which he didn't commit when he had the opportunity. - Helen Rowland, A Guide to Men, 1922

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest