Skip to main content Accessibility Feedback

High Performance Websites

This article has been replaced by Wicked Fast Websites, a three-part series with more tips, tricks, and tools for building high performance websites.

In the age of mobile, web performance is a design feature. If your site isn’t fast, people will just leave.

Today, I want to share a few simple things you can do to dramatically improve the performance of your site. Using these techniques, I’ve gotten Go Make Things to load in less than a second, running WordPress on inexpensive shared hosting.

The Steps

We’ll be doing a few things:

  1. Concatenate. Combining like files together.
  2. Minify. Removing the spacing, line breaks and comments from files.
  3. Smush. Removing unneeded data from image files.
  4. Icon Fonts. Icon fonts are a lighter, faster alternative to image-based icons.
  5. Compress. Reduce file size by up to 70 percent.
  6. Cache. Telling browsers to keep static assets stored locally so that they doesn’t have to be re-downloaded every time they visit your site.
  7. Page Structure. Adjusting the location of CSS and JavaScript files for faster rendering.

Let’s get started…

Concatenate

One of the biggest bottlenecks in page load time is in downloading the actual files for your site.

Each HTTP request adds additional load time. It’s actually faster for a browser to download one 100kb file than it is to download two 50kb files. By combining similar file types together, you can improve page performance.

When you can, combine all of your javascript into a single .js file. Rather than loading separate .css files for your base styles, small screens, bigger screens and so on, combine them all into a single stylesheet with media queries.

And don’t think you can cheat by using the @import rule. That still requires additional HTTP requests.

Minify

Minifying is the process of removing spacing, line breaks and comments from your CSS, HTML, and javascript. Though it might not seem like a big deal, removing all those unused elements can decrease the size of your files by 40 percent or more.

For this, you’ll need Google Chrome and the Page Speed Add-On.

Minify Your CSS

In Google Chrome, run the Developer Tools and click on the “Page Speed” tab. Then click “Analyze.”

You’ll be given an overall score, and a list of things you can do to improve your score.

One of the items on the list will be “Minify CSS.” Click it. Under “Suggestions for this page” is a link to “see optimized content.” Follow that to get a minified version of your CSS provided by Google.

Rather than overwrite my human-readable CSS, I paste the minified code into a new file called style-min.css. Reference that in the header of your HTML.

Minify Your JavaScript

In the Developer Tools Window, click on “Minify Javascript” and repeat the process above to access a minified version of your script from Google. If you’re using jQuery, Google also provides a minified version of that you can use.

Paste the minified code into a new file called js-min.js, and change the link in your HTML to that file.

Minify Your HTML

There are a few ways to minify your HTML.

If you’re building static webpages, the Developer Tools Window in Google Chrome will contain a “Minify HTML” recommendation. You can follow the same process as with the CSS and JavaScript.

If you’re using WordPress, there’s actually code you can add to your functions.php file to dynamically serve minified HTML.

Between <?php and ?> add this bit of code (.txt file), courtesy of DVS. If you view source after making this update, you’ll see a message at the bottom of the page telling you how much the file was compressed.

One issue I have discovered: If you use inline AJAX, this code may prevent it from working properly. If you find this to be the case, set protected $compress_js = true; to “false” instead, and it will leave javascript uncompressed.

Smush

Images in their raw form often have a lot of extra but unneeded data in them. This makes the file sizes up to 60 percent bigger than they need to be.

“Smushing” images is the process of removing that unneeded data and optimizing them for web viewing.

Smushing Apps

So how exactly do you smush an image? There’s an app for that!

I downloaded ImageOptim, which is unfortunately Mac only. It’s a simple drag-and-drop application, and actually shows you how much smaller the file is after smushing.

If you’re on a PC, you can also use Smush.it, a web-based app from Yahoo.

Better file types

It’s worth noting that I’m not just smushing my images, but also making smarter decisions about file types.

Historically, I would save all of my images as PNGs files. PNG is a lossless image format, so it keeps graphics sharp and crisp (as opposed to the lossy JPG format). However, PNGs are also substantially larger than JPGs.

For icons, PNGs make a lot of sense (or used to – more on that in a minute). But for something like a photo of people or places, which already have a lot of noise in them, a JPG is actually a better format because it’s much smaller in size.

Icon Fonts

Rather than using PNGs for my icons, I actually use an embedded web font.

Using the IcoMoon app, I was able to create a custom font set with just the icons I need. It weighs in at just 4kb and results in just a single HTTP request, which drastically improves performance.

And because I’m loading a font and not images, they can be scaled smoothly to any size, styled easily using CSS, and don’t get distorted on retina displays. If you don’t go the icon font route, you should use image sprites instead.

Compress

In Apache HTTP servers, .htaccess (hypertext access) is the configuration file that allows for web server configuration.

With a simple modification to your .htaccess file, you can tell the server to send your files compressed as gzip files. This reduces file size by about 70 percent.

Learn how with this tutorial on GitHub.

Cache

Setting cache headers tells browsers to keep static assets stored locally so that a visitor’s browser doesn’t have to re-download them every time they visit your site.

This is also something that’s done using the .htaccess file. Follow these instructions on GitHub.

Caching for WordPress

If your site is powered by WordPress, there’s an additional step you can take that will dramatically improve performance.

Each time someone accesses your site, WordPress dynamically generates an HTML page for them using server-side processing. Caching your WordPress files will create static HTML pages ahead of time that get stored on the server and sent to visitors. This is a lot faster than WordPress creating a fresh page each time someone visits your site.

There are a few plugins that do this for you, most notably WP Super Cache and W3 Total Cache. Both require a bit of tweaking and tailoring, though, and can be a bit confusing to set up.

I prefer Comet Cache. There’s only one thing you really need to do: switch it to on.

Comet Cache automatically updates pages every hour (in case content has changed), and for people who are logged in or who have left comments, it serves them the dynamically generated pages instead of cached ones.

This reduced my page load times by about 30 percent.

Page Structure

There are two last changes you should make: Make sure you load your stylesheet at the top of the page and your JavaScript at the bottom (when possible).

This doesn’t make the page download content any faster, but it does help browsers start displaying it more quickly.

In order to avoid having to redraw elements, browsers will wait until the stylesheet is loaded before displaying content. If the CSS file is one of the last things to download, people who visit your site will stare a blank page for longer.

Browsers typically download multiple files at once. However, some browsers block other files from downloading while a javascript file is being loaded. Putting your scripts at the bottom of the page ensures that more of your content is downloaded and displayed as quickly as possible.

Your High Performance Website

These techniques took me about 30 minutes to get set up. This site now loads in under a second, running WordPress on inexpensive shared hosting.

Your performance may vary a bit (I also have an extremely small CSS file and don’t use jQuery on this site), but these tips should still make a big difference.

Referenced & Useful Resources

  1. Web Performant Wordpress by Dave Rupert.
  2. Front-end performance for web designers and front-end developers by Harry Roberts.
  3. The Page Speed add-on for Google Chrome and Firefox.
  4. YSlow, another website performance tester from Yahoo.
  5. Pingdom, another tool to test page speeds.
  6. Pre-minified jQuery and other code from Google.
  7. Easy Trick to Minify HTML by DVS.
  8. ImageOptim, a Mac app for smushing images.
  9. Smush.it, a web-based app for smushing images from Yahoo.
  10. IcoMoon, an amazing icon font app.
  11. My tutorial on using icon fonts.
  12. Image Sprites: What They Are, Why They're Cool, and How to Use Them by Chris Coyier.
  13. Best practice for speeding up your website from Yahoo!