Search Results

Why a Web page is like a blueberry pie

Yesterday afternoon I Tweeted this: I thought it might be worth explaining what I was talking about, using a metaphor lots of people would understand. So, consider a blueberry pie. To bake a blueberry pie, you assemble your ingredients, do some mixing and combining and stick it in the oven. Let’s say, though, that after [...]

Yesterday afternoon I Tweeted this:

Poking the DOM with PHP. I know YOU all knew about it but *I* just found it and it's wonderful.July 20, 2010 2:01 am via Echofon

I thought it might be worth explaining what I was talking about, using a metaphor lots of people would understand. So, consider a blueberry pie. To bake a blueberry pie, you assemble your ingredients, do some mixing and combining and stick it in the oven. Let’s say, though, that after the pie is out of the oven and cooled, a picky young man with short blond hair says “but Mom, I wanted cherry pie!” Being the outstanding parent you are, you lift the top off the pie, pick out every single blueberry and replace them with cherries. (I know, just go with it.) Remember that, it’ll be important in a few minutes.

On another day, you’re preparing your pie ingredients when the aforementioned picky young man again requests a cherry pie instead of blueberry. This time, you can replace the blueberries with cherries before mixing the ingredients and baking the pie. Same result, but one is clearly easier and less disruptive on the final product.

Finally, the pie is done and you cut a slice. Look at the cross-section of that slice of pie. You have a crust, filling, berries, maybe some ice cream or whipped cream on top. That’s the structure of the completed pie that’s ready to eat.

How does this tasty metaphor apply to Web pages, and specifically to my not-entirely informative Tweet?

A Web page, like a pie, has a structure that can be examined. It has text, images, colors, different fonts, maybe some embedded video clips. These are all elements that make up the structure of the Web page. This structure is called the Document Object Model, or DOM–for purposes of this post it’s not important what that means, but where you see “DOM” you can read “bits and pieces that make up a Web page.”

Let’s say you want to change one of these elements. You could do it after the page has been loaded (the Web browser is showing the page) or you could do it before the page has been sent to the Web browser. Changing the elements of the Web page after it has been loaded is usually done with JavaScript, which is code that runs in the Web browser and is analogous to removing the blueberries after the pie is baked. Changing the elements before the Web page is sent to the browser is, in this instance, done with PHP, which is code that runs on the Web server. This is like adjusting the pie recipe before mixing the ingredients.

The major difference, and why I was excited to discover this capability of PHP, is that adjusting or changing the Web page after it’s been loaded (with JavaScript) is about as simple as removing blueberries from a fully-baked pie. It depends on the capabilities of the Web browser viewing the page and in some cases of the OS running the Web browser. It also adds to the total amount of data sent from the Web server down to the browser (all content [text, images, video, etc] plus the extra code which runs after the page has loaded) and is just generally inefficient.

On the other hand, the ability of PHP to change the contents and structure of a Web page while its still in ingredient form and hasn’t been mixed and baked means that what’s sent down to the Web server is already what I want it to be and I can tweak it as much as I need to before it’s served.

This is a drastic oversimplification, of course–there are plenty of good reasons to fiddle with the DOM using JavaScript once the page has loaded; Web applications like Gmail, Twitter and even WordPress use this capability all the time to change, add or delete elements of the page without making a round trip back to the server. There are also lots of applications where large-scale preprocessing is done on the server with PHP and final tweaks are done in the browser, often depending on the specific browser and version being used. However, the pie metaphor does make a good high-level explanation of this aspect of Web page development.

At least, I think it does. What do you think? Comments welcome.

Comments (1)

Fringemas!

Leave a Comment

Live Election Results

I’ll be on MSNBC.com throughout the day and probably home by 4-ish for the first returns. What about you?

I’ll be on MSNBC.com throughout the day and probably home by 4-ish for the first returns. What about you?

Leave a Comment

The Obama radio ad you probably haven’t heard

From TPM Election Central at Talking Points Memo, originally linked from MaddowOnline: To our knowledge the Obama campaign didn’t release it to the national press, but Team Obama is airing a new radio spot in Wisconsin — the home of Harley-Davidson — attacking John McCain over his recent quip at a biker rally that he’d [...]

From TPM Election Central at Talking Points Memo, originally linked from MaddowOnline:

To our knowledge the Obama campaign didn’t release it to the national press, but Team Obama is airing a new radio spot in Wisconsin — the home of Harley-Davidson — attacking John McCain over his recent quip at a biker rally that he’d much rather listen to the ‘roar of 50,000 Harleys’ than the cheering of 200,000 Berliners.

The spot quotes McCain’s joke, then calls him a phony for opposing a requirement that the government buy American-made motorbikes. ‘But when it comes to his record,’ the announcer says, ‘American-made motorcycles like Harleys don’t matter to John McCain.’

Click below to listen to the ad.

Leave a Comment

Updated network map

Updating this post from earlier this year, here is the current network map done on Gliffy. gliffy_did = “1073358″; embedGliffy(); Changes/additions from last time: Added Apple MacBook Pro notebook (GJETOST) Added Maxtor 500GB NAS box (EDAM). Still need to switch this to static IP addressing. Added Buffalo DriveStation Combo 4 1TB eSATA box (MOZZARELLA) for [...]

Updating this post from earlier this year, here is the current network map done on Gliffy.


Changes/additions from last time:

  • Added Apple MacBook Pro notebook (GJETOST)
  • Added Maxtor 500GB NAS box (EDAM). Still need to switch this to static IP addressing.
  • Added Buffalo DriveStation Combo 4 1TB eSATA box (MOZZARELLA) for DirecTV DVR storage.
  • Removed the “TBD” file server from the diagram, since now with the 500GB NAS there is no need for a full-fledged file server.

Total live storage:

Device Capacity
BRIE 80GB
GJETOST 200GB
STILTON 500GB
EDAM 500GB
GuestRoom (DirecTiVo) 500GB
LivingRoom (DirecTiVo) 500GB
MOZZARELLA 1TB
Total: 3.28TB

Not all of this storage is immediately available for arbitrary use, but if I really wanted to I could ftp to either of the DirecTiVo boxes or mount the eSATA box as FireWire on the Mac. Also, somehow the two DirecTiVos don’t have cheese names. How did that happen?

Leave a Comment

Easy AdSense by Unreal

Project Insomnia is Digg proof thanks to caching by WP Super Cache