A simple page
January 11th, 2007Have you ever been to Yahoo? I bet you have. Yahoo used to be the #1 search site. It is still very popular, but has expanded to include many different services and functions.
Yet still, the home page isn’t that complicated. There’s quite a bit of stuff there, but it is organized ok and you can easily follow where and what things are. It’s mostly a bunch of links to other Yahoo pages and some ads. In fact, you can print it out onto one piece of paper. Nothing big and complicated, right?
Have you looked at the source or the code? Big difference. If you view the page source and print, you will get 28 pages of html, css, and javascript! That’s what it took to create that simple little page you see. This isn’t even the ‘hidden’ server side code that is run and executed before the web page is sent to your browser. That is probably double the amount.
This is where a lot of confusion has come in, so let me explain a bit. The html, css, and javascript that we are used to and that you see in the source of the web page is all client side code. This means the web server sends it all to your browser and your browser reads and executes it. This is happening all locally to you, the client, so we call it client side code.
Server side code is something like PHP or ASP. This is code that the web server reads and executes on the server before sending anything to you, the client. What this code typically does is makes decisions on what html to use and send, it connects to the database and gets dynamic content to fill in and create the web page, and it may do many other functions that happen on the server side of things. This is all before sending anything to your web browser.
When you look at the Yahoo page, each one of those links and ads and bits of text is stored in a database. The server side code retrieves it and creates the web page to then send to you. Typically, we find that server side code can be 2x - 4x as much code as client side code. Yet, you can create a simple static html page that looks identical to this without a bit of server side code. So why so much code?
You have to remember, that creating static content and pages makes it more set in stone, per se. Every person to visit that page gets the same content. You then have to change it again to get new content. Doesn’t sound too bad, right? Think of this - Yahoo has thousands of pages with new ones added daily and it has thousands of links in it’s database. Do you want to search through it to find the page name to link to? Didn’t think so.
With dynamic code, everything is stored in the database for more easy retrieval. This means the pages are constantly updated as data in the database changes. This makes for much more easily managed web sites with new data and always the best data.
As another example, I worked with someone once to create a dynamic online questionaire maker. Fairly complicated bit of coding for what we wanted to do. The designer spent 4 or 5 hours designing the couple screens we would use. This was the layout and look of the app. We went over it and tweaked it a bit. I estimated it would take another 16 - 20 hours of work to make it all function and make it dynamic. Before we did that, we wanted to show the client to ensure we wouldn’t have a problem later.
The client was very pleased and excited by it. They asked ‘So can we start using it?’. We had to answer No, we needed to make it work. The client didn’t understand, it looked like it was all there. After explaining what we had and still needed to do they reluctantly said they’d wait. When we were completed we went back to show them to functioning application. They were a little bewildered. ‘What did you do, it still looks the same?’ We had a hard time explaining that yes, it would look the same as what we did was add the server side code to make it all work.
So, server side code doesn’t show and may be hard to tell what it does. But when web pages are taking 28 printed pages of code, you can bet the scripting server side code is quite extensive. If you can see a difference, the programmers didn’t do as well as they should have.
Another interesting point, did they really need that much code for the Yahoo page? Arguably not. Much of the code is CSS and looks like some browser specific stuff but also some things added after other stuff was already there. There may have been good reasons for what they did, but it’s usually best to try to limit the amount of browser specific code you get.