gregdoolittle.com

chronicling the fate of a warrior: Ajax the Great

January 19th, 2007

I bought my text book for my Ajax class (I also bought my book for my Database class, but hey, that’s just not exciting!). I hope to document my experience learning Ajax in this blog. The class doesn’t begin until March 21st, but I’m planning to work through as much of the material as I can before then, so I can apply it to my new job.

Just finished the Chapter 1 tutorial. Some points to remember:

•The main goal of using Ajax: to reduce the need for data transfer within a web page, therefore increasing your site’s ability to react quickly to user activity.
•Ajax should be able to function in every JavaScript-enabled browser.
•The Ajax request object has not been standardized among browsers. In Firefox/Safari/Opera/IE7, you use the XMLHttpRequest object. In IE6 you use ActiveXObject(”Msxm12.XMLHTTP”). And in IE5 and earlier you use ActiveXObject(”Microsoft.XMLHTTP”). You should account for this every time you create an Ajax request object.
•An Ajax-script is usually called by an event handler (onClick, onChange, onMouseOver, onBlur, onKeyUp, etc.).
•The browser keeps track of a request’s “ready state”. When the ready state is equal to “4″, it means the request is done retrieving information. The DOM aspect of the script must wait until this ready state is achieved. Otherwise, the script will finish running before the information is available.

Every Ajax script will require an object to hold the request, followed a bit of browser-sniffing to apply the appropriate type of Ajax object:

var request = null;
 try {
  request = new XMLHttpRequest();
 } catch (trymicrosoft) {
  try {
   request = new ActiveXObject("Msxml12.XMLHTTP");
   } catch (othermicrosoft) {
    try {
     request = new ActiveXObject("Microsoft.XMLHTTP");
     } catch (failed) {
      request = null;
     }
   }
 }
 if (request == null)
  alert("Error creating request object!");

Usually followed by these lines of code:

var url = "example.php";
request.open("GET", url, true); // true means this is an asynchronous request
request.onreadystatechange = updatePage; /* updatePage() is a function that will use DOM
methods to alter the page hierarchy */
request.send(null); // the request.

If you’d like to see my first, and very dorky, Ajax “application”, you can get to it here (update 01/21/07: just added a random parameter to the URL of the request object, which fixes a bug in IE and Opera). In this case the amount of data transfer saved by using Ajax (as opposed to requesting an entire HTML file) is so minimal that it hardly justifies the time spent constructing the Ajax script. But imagine that this feature was part of a page that did have a lot of elements (say, a couple of 8MB image objects). In that case, using Ajax for such a minute section of a page would be worthwhile, because it would avoid reloading the large amounts of data sitting around elsewhere on the page.

the css of css

November 9th, 2006

i had an idea a while back. basically i wanted to include variables in my CSS. the point was to extend the ease of updating a site’s style.

in a CSS document you usually use the same color value for multiple elements. when you want to update the color scheme of your site’s design, you have to do a find-and-replace for all occurrences of the old color, swapping it out with the new color. instead of updating every instance of a color, an image URL, or a typeface, imagine how easy it would be to do if you could just update your variables which you had declared at the top of your document.

i thought i had a great original idea. i had even tried implementing it with JavaScript, but to no avail. tonight i was brushing up on the SiFR type technique, when i came across “my idea”, implemented and documented by Shaun Inman. basically, he’s figured out how to do exactly what i thought i invented, and named it: CSS-SSC.

this is the basic syntax:


@server constants {
constantName1: constantValue1;
constantName2: constantValue2;
}

selector {
property1: constantName1;
property2: constantName2;
}

you can also import the constants from an external file:

@server url(constants.css);

if this interests you, read the full article. it looks like in addition to using this syntax for variables, you will also need to add a special PHP script to your CSS directory, and tell your server to parse your CSS files using the PHP interpreter by modifying the .htaccess file.

why .mobi?

October 21st, 2006

I got this ad from my webhost in my email:

Millions of people have the potential to visit your Web site from their mobile devices – are you ready for them? With NEW .MOBI, the world’s first mobile-optimized domain, you can reach out to an entirely new, high-tech audience that’s waiting to connect with you.

I’ve heard about .mobi before, but I really don’t get it. First of all, why would you need a mobile domain for your site? Who will remember that it’s .mobi and not .com? You’re going to have to register .com anyway! And since you’re going to have a .com address, you can just have a mobile stylesheet or use browser detection to redirect cell-phone users to a mobile-friendly version of your page.

secondly, unless you have a blackberry or a sidekick, i find internet on the phone to be completely annoying! the tiny screen, the numeric keypad… basically, surfing the web on a mobile phone is a pain in the neck. it’s also ridiculously expensive. if you can afford a cell-phone you can probably afford internet access at home. there are a few ocassions where you might need to surf the web on a cell phone: 1. to check your email on your boring commute home (but can’t you read a magazine, or just wait until you get home!), 2. to look up someone’s phone number (which is probably the ocassion where the price of internet on your phone is worth it, given the ridiculous rates that directory services charge. 3. to check the traffic on say, sfbaytraffic.info. but on that site you really need to have a mouse to get all the information. calling 511 is cheaper.

so there you go. thank you monolithic phone industry. i might sound like a crotchity old man, but i just don’t see the point of mobile-web-surfing. i’m sure there are plenty of gadget-dependent type A personalities out there, plenty to make a profit off of… maybe it’s time i learned some WML. i’m sure it would straighten out a lot of my confusion.

battle of wysiwyg: MacroAdobea v. Microsoft

October 21st, 2006

I don’t use Dreamweaver. I’m not really a fan of wysiwyg editors. I write all my code either by hand, or using syntax highlighting with GNU Emacs (hooray for open source!). But interestingly, today I heard from the PWD Podcast that Microsoft is coming out with their own version of Dreamweaver: Expression. I’m hoping for a browser-war-style contest where both sides of the force push each other to creating some neat new technologies. It’s good to see some competition with heavy-weights such as Adobe, even if it is competition from Microsoft.

The beta of MS-Expression is currently downloadable for free, but only exists for people running Windows XP. I use a Mac, so this won’t even affect me, I’m just passing the word along. I suppose I’ll keep using good ‘ole emacs for now…

plug for my new host

October 4th, 2006

i needed a place to put my content. i’d asked around to see if anyone i knew had any suggestions for webhosts, and someone asked me: “why don’t you just set up your own server?”. i’ve always had a sort of nerd-fantasy of doing that, but after careful consideration, the logistics just didn’t add up. paying someone else to host my site is way cheaper than setting up a server, and a lot less to worry about for my small scale projects. i would have to set up a higher-bandwidth package from comcast, as well as buy a machine to act as a server. then there’s the whole installing apache and configuring the server, which would undoubtedly be a good learning experience (and i’m confident it’s something i could do), but i just don’t have the time or resources to do it right now.

i went with a host called bluehost.com. they’ll be hosting cssfoundry.com for me. the main benefits of bluehost: 1. no ads (godaddy.com tried to put ads on my site!) 2. i can ssh into my account. 3. can host up to 6 domain names on the same account. 4. free sub-domains. 5. free MySQL tables. the weird things that are annoying: (there really isn’t a whole lot to complain about!) 1. price is higher (but seems worth it so far), 2. the favicon doesn’t carry through to subdirectories of the site… um.. aside from that it’s pretty good… (remind me to update this after using bluehost for a few weeks, i’m sure i’ll have a real complaint or deeper opinion by then).

two thumbs up

October 3rd, 2006


i recently finished reading a book for css design, by Dave Shea and Molly Holzschlag. i’ve never done a book review, so this is a first attempt:
the title is rather cheesy (the zen of css design), but the book is fantastic. if you’ve never heard of the “css Zen Garden” it is definately a site worth checking out. Started by Dave Shea in 2001, the site demonstrates the promise of CSS’s ability to control all design aspects in a remote document. Designers are given an HTML file which they cannot modify, and are asked to create a .css file that stylizes every element on the page. The best entries are featured on the site (sort of the “prize” for winning). The book goes through about 40 different css zen garden proposals and dissects the code and techniques that underly. The book starts from an art theory perspective and ends with some technical hacks for getting around different browsers. Quite a good mix of content. You can read the book from cover to cover. Two thumbs up.

no more godaddy.

September 28th, 2006

it happened three times. godaddy took down my site. i followed up by calling them to ask why they took it down, and the first two times, the said they weren’t sure, and put the site back up. this last time, they took it down for good (i presume), and sent me this email:

Dear Sir/Madam,

It has been brought to our attention that your scripting for cssfoundry.com is blocking the advertisements that are placed on our free hosting accounts. Our Abuse department has suspended your account as this is a violation of our Terms of Service.

Thank you for your understanding in this matter.

Regards,
Advanced Hosting Support

so, the tug-of-war between me and godaddy.com is over. and while i still believe my fight was worth fighting, i can’t help but feel a bit humiliated by my defeat. i’ve officially breached the terms of service with my workaround that disabled their ads. i feel like a petty criminal.

hopefully, this will all be fixed when i find a new web host.

<div id=”GoDaddyTriedToScamMeAndIBeatThem”></div>

September 17th, 2006

Victory is mine.

After spending quite some time on the phone with GoDaddy.com’s customer service reps, complaining about what I thought was a mistake on their part, I realized I had not read every word in the fine print.

It all started when they sent me yet another a promotional email last week; the subject was: “Exclusive Savings - .COM just $6.95/year”, and the fine print said something about a free web-hosting package if you signed up this weekend, valued at $96.00. Since I had known GoDaddy to occasionally have absurd offers for web hosting packages, I thought: sure, this will be a good opportunity to start that website I’ve been thinking about. So I registered for the site.

I designed a logo on my desktop with CSS (as opposed to in photoshop), this way the file size would be much smaller. I felt so smug. A few hours after registering, I uploaded my logo to my new site (www.cssfoundry.com). I always get a little thrill out of seeing my stuff through an http request, as opposed to from my desktop, so of course I looked at my site. typed the URL into the browser, and WTF DO I SEE? THERE’S ADS FOR GODADDY ON MY PAGE!!!!! all across the top of the page about 100 pixels in height, there are ads for go daddy! How did these get here? They weren’t in my code, and I sure as heck didn’t sign up for them. I signed up for hosting that was worth $96.00, not some crummy free geocities, or aol sponsored site. I mean, I paid money to have the site! You can imagine how ripped-off, and how stupid I felt when the guy on the phone said that the free hosting was supposed to be free “ad-supported” hosting. How that could be worth $96.00 is beyond me. Faulty advertising at its best, I thought. Oh well, I’ll have to switch hosts….

…but wait! I just thought of something. Why don’t I just cover their ads with a div element? This way, the ads would not be visible; people would only see the div element layered on top of the ads. The ads wouldn’t even be clickable. It was such a great plan, because GoDaddy wouldn’t get to make money off of my site, and my visitors wouldn’t be bothered with their ads. So that’s what I did. GoDaddy tried to scam me, and I beat them, here is the CSS:

#GoDaddyTriedToScamMeAndIBeatThem {
	position: absolute;
	top:0px;
	width: 100%;
	height: 101px;
	background-color: inherit;
}

and the corresponding html, of course:

<div id="GoDaddyTriedToScamMeAndIBeatThem"></div>

What a satisfying feeling… I just hope they don’t catch on to me. At least for the time-being, I can say that I won. My little way of “sticking it to the man”.
;)

firefox - web developer’s toolbar

September 7th, 2006

i just discovered the web developer’s toolbar for firefox. hmm.. how do i describe it to someone who’s never used it? well, basically it’s like being able to take an x-ray of a webpage. there’s tons of viewing options to demystify the layout of tightly-knit/transparent page layouts. a very cool tool. i wish i had heard about sooner, it’s very worth your while if you have not seen this before.

boagworld.com

August 24th, 2006

i just found my new mentor for web design: boagworld.com. it’s a pretty cool site for beginners. they cover a lot of stuff you would never talk about in a class. and they stay very current with web standards. neato.

fall semester CSM

August 18th, 2006

i’m taking intro to javascript as well as php (with mysql) this fall. both classes are online, which is pretty convenient. javascript should come fairly quickly since i took intro to programming with java. but php is kinda scary. i’m a little worried that this particular class will be too much all at once. it seems like a really cool language, based on how much you can do with it, and how simple everything looks on paper, but it’s also intimidating. i don’t have the required pre-requisites, but the teacher said i could take it if i’m willing to work really hard. i’ve never used mysql, so that’s another intimidating factor.

i’ve been lagging on syndicating this journal to my website. i need to officially put a hold on that idea. i’ve been meaning to spend time on it, but with weddings and birthdays and everything else, i’ve just been too busy. at some point during this semester, i’ll take another look at “php-embedding” this site. i don’t have time now (especially with school starting), and it’ll be easier then.

i set up a little mail() script on my website. i’m a little afraid of it being abused so i don’t want to post a link to it. this was my first (server) script; it was really exciting to see the script work when i sent myself an email from my domain. now i’ve got to figure out how to validate input fields… that should be a challenge!

back to 1996 / i’m 10 years too late

August 10th, 2006

i’m faced with the fact that i don’t have a whole lot of web design experience. i also have no formal design education (trust me, a bfa and design degree are two very different things). the skills i have right now would be respectable if it were 1996… but it’s not. when i look at job postings, almost everyone asks for some server-scripting skills, and i have none. my current job has nothing to do with the web.

my only advantage could be drawing. i need to do more of it with my web design. despite the my lack of server-skills and advanced web-design skills, drawing is really the only possible edge i have over real-deal computer science people (except for the ones who can also draw!). i’ve been spending most of my free time trying to learn web stuff, and not drawing… so my drawing skills have been waning. i really should be exploiting my access to illustrator at work. this is my new self-imposed ultimatum: make one vector “object” per day (just a tree or a bird or whatever; something simple) and post one of them in this journal each week. we’ll see where it goes from here… hopefully i can start a library of my own custom vector art…

feels like drowning, looks like swimming…

July 28th, 2006

i thought i totally bombed my test. i just found out that i got a 90.5, not nearly as bad as i thought. i agree that grades don’t mean much, but it shows i studied, and that i have at least a basic grasp of the material.

right now we’re doing xsl / xslt / xpath, which i find to be really useful. from the mac perspective, it’s great. i can finally see all of this xml stuff by using the transform to html method in xsl. i’m wondering now how many “html” pages that i look at are actually xml documents transformed with an xsl-template. as a project for myself, i’m going to try to write an xsl document that will syndicate this journal into my website, using an rss-feed with an xslt. if i can get that done quickly, i’ll know that this class is beginning to pay off.

i also found a pretty cool site with lots of interesting rss / xml feeds. i think part of the beauty of xsl is the ability to flow text into your own choice of formatting, and ability to control the information filtering. after i’ve gotten this journal to flow into my website, i’m going to try to do some sort of graphic display based on a live database… later on down the road, i need to figure out how to turn an html doc into xml. that way i can write a cool mashup, taking xml and html from two different sites to build a third site that integrates the data into a new and more useful perspective on the information (something similar to this one).

xml + mac

July 7th, 2006

xml class is going swimmingly, despite being the only person in the class using a mac. normally being on a mac isn’t a disability, but with xml, there’s a number of issues that still haven’t been resolved (and how long has xml existed!). it’s hard to find a good xml-editor for a mac, and most osx browsers don’t “yet” support a number of features of xml (general entities, namespaces, multiple schemas)…

the silver lining is that i’ll be the only one in the class with a strong sense of how xml files look on OSX. i’ll know what not to use, to ensure that my pages are cross-platform compatible.

Powered by WordPress