Apache + Compression = Faster Website

October 14th, 2009

A lot of web developers tend to overlook or ignore the  file sizes of the files that compose their websites.  I’ve seen many websites that are well over a megabyte for just the home page with all its components.  I’ve even seen a few that were over 3 megabytes.  While most americans have broadband of some fashion, there are still a significant portion (~20%) that do not have broadband, and even those that do will get impatient waiting for a page to load, and may click off before you have a chance to wow them with your content.

I tend to use several techniques to keep my overall document size reasonable:

  1. Compressed Images – JPEG (for complex images) between 40 and 65 percent quality, depending on where compression artifacts become too noticeable; GIF (for simple images) color palette restrictions between 8 and 128 colors, depending on where the artifacts become too noticeable. Of course I also use PNG images where a really good alpha channel is needed, but I use them sparingly, as full alpha transparencies dont compress well.
  2. Minified Javascript and CSS files.  I like the YUI Compressor for this.
  3. Server-side compression.   Even minified files can be squeezed even smaller with the use of server-side compression.

Server-side compression is super-simple to implement, as long as you have access to an .htaccess file or a friendly server administrator.  Here’s a syntax that works for me on a couple of servers I run (This is Apache specific, for other servers find a mod_deflate equivalent):

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE text/x-js application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

The two AddOutputFilterByType lines can be combined into one or split up however you choose if you’re a stickler for keeping your text in configuration files readable. This can be inserted in the virtualhost definition or in your .htaccess file.  Using this alone, I consistently shave off between 60 and 100 kilobytes off my download size.  Enjoy!

And now, for something completely different…

October 7th, 2009

So rather like the proverbial mechanic’s car, the web developer’s own website can languish unless he or she makes it a priority.  So after 5 1/2 years, I’m finally releasing a website under the ThreeBit flag.  I’m going to be transplanting some articles from my personal blog here to sort of get things off the ground, and will go from there.  So welcome to the new ThreeBit Media website!

Designing for email, and feeling dirty because of it.

February 23rd, 2009

Back in my first Designing For Email post, I discussed workable dimensions and some common-sense techniques when you’re approaching designing for email. Most of that still holds true, but I’ve discovered an unpleasant lack of support in a few email clients for an important bit of CSS: floating, clearing, and margins. The lack of this one bit makes good design wholly in CSS nearly impossible. I’m officially peeved. What’s really weird is MS Outlook. Outlook 2003 supports floating just fine. Outlook 2007 does not. So what does this leave me with? Table-based design.

Yeah, I know. Seriously. After all this time when CSS has (finally!) become a standard method of layout. When people are finally getting the whole point of separation of concerns when it comes to content versus layout, and browsers are getting good support, and for the most part I can get my designs to be pretty consistent across browsers without much effort as long as I closely follow the rules… I’m having to retrofit my CSS-based layout into a table-based design.

As I was coming to grips with this I did a sanity check by looking through the last few months of my inbox and looking at the adverts (non-spam) I’d recieved. A quick look at the source confirmed that they were ALL table-based. Dang. And now the fellow across the hall is making fun of me. He knows how dirty I feel for having to violate standards to make something layout correctly. Oh well. For what it’s worth, I did stumble across the Email Standards Project, which is what confirmed that Outlook 2007 and Gmail (!) both lack support for floating/clearing. So, have fun dusting off the table-based design knowledge you’d accumulated and then happily buried when CSS finally became a viable alternative.

Designing for Email

December 9th, 2008

My company is about to launch an email newsletter and I began to wonder about what layout dimensions I should shoot for. I’ve not given it a lot of thought in the past, but as I’m building a template for repeated reuse, I’m now giving it a few neuron cycles. There are a couple of major issues with designing for email that are reminiscent of the especially difficult browser-compatibility problems that have caused multitudes of web designers to rage and wail and burble incoherently. These issues are essentially this: 1) email clients don’t give you a lot of room to work in; and 2) email clients are not full-featured browsers.

Let’s talk about physical dimensions first. An email client is designed and navigated differently from a browser. The “chrome” on most modern email clients include not only the toolbars and menus, but an entire left-hand column used to navigate mail boxes and other features. This column alone consumes a couple hundred pixels of horizontal real estate. Vertically, the space is usually split in half so that the user can see a list of messages in the upper half and then view them in the lower. When all this is taken into account while still designing for a small common screen resolution on the order of 1024×768, you wind up with a usable viewport more in the neighborhood of 650×300.

Now take into consideration that the (X)HTML rendering capabilities of email clients are not necessarily on par with fully-featured browsers. For security and speed, most email clients have a very limited set of supported browser features. Most won’t display flash, few support animated gifs, and JavaScript support is typically limited. Thanks to spam, you’re not even guaranteed any images will display at all, but fortunately, most of the time plain-jane images will load just fine.

So here are a few guidelines for (X)HTML-formatted documents delivered via email:

  1. Keep your overall width between 600 and 650 px. This should be old-hat to those of us that were designing around the turn of the century, and will be an interesting excercise to the neophytes.
  2. Remember that the “fold” on an email client is likely going to be around 250-300 pixels down the page, so make sure you have something above the fold that will make your user want to scroll.
  3. Keep it simple. Avoid JavaScript. Use well-supported (X)HTML and (inline or on-page) CSS only to aid your presentation.
  4. Keep it standards compliant. The same “failing gracefully” principals apply to email that apply to browsers. However, there’s the additional “standard” of making sure you have a text-only version of your email ready to fly along with the HTML-formatted version.

Finally, a note about content. A rule that used to apply to physical newsletters is also applicable to email newsletters. A friend of mine used to tell me that “A good newsletter can be read between the mailbox and the trashcan”. Be brief in your email content and link frequently to expanded content on your website. Enjoy!

UPDATE! I’ve discovered that Outlook 2007 and Google’s Gmail don’t support floating and clearing. This makes design using pure XHTML and CSS very painful. I’ve got new post about this issue and my dismay here.