What I learned at WordCamp Philly

Posted by Pete Schuster on

This year at WordCamp Philly, I learned a lot. Not only was it my first WordCamp, it was my first time presenting in front of a crowd of my professional peers. I was extremely nervous, but everyone in the room seemed to cope with my uncomfort, and I got a lot of well wishes from the audience at the end. Besides gaining experience as a speaker, I also pickup some tips from the community. There is one tip in particular that I’d like to share and thats the wp_enqueue_style function.

What is wp_enqueue_style?

The core function wp_enqueue_style, is a way to call your stylesheet so WordPress is aware of the stylesheet you are using. By doing so you can prevent that stylesheet from being called multiple times say by a plugin etc. The most powerful feature, however, is that offers you the option of using a version number.

I’ve recently been doing a lot of research into page speed and Google webmaster best practices. One thing I’ve really focused on is serving your users condensed, minified, and compressed javascript and css. Having multiple stylesheets for print, mobile, etc is bad practice when you can have one stylesheet and use media queries to serve them appropiatly. Another bad practices would be not to condense the stylesheets, etc of plugins your using, say for a lightbox. Serving your user one stylesheet lowers the amount of HTTP Requests to the server, and improves the overall speed of your site.

Versioning Your Stylesheet with WordPress

So where then does versioning come in? Well say you’ve condesed all your stylesheets into one master version, you’ve run that file through the YUI compressor and you’ve saved it as a separate file say, style.min.css. What versioning can do is help your users make sure they’re seeing the latest version of your CSS.

When a user comes to your site, they cache your stylesheet and javascript, so each page they visit, the don’t have to redownload the same file. The file gets stored locally, and increases page speed. But say you’ve made a change to the size of some elements on your site, but the user still has that stylesheet cached, your site may appear broken until that user does a hard refresh on their browser. Versioning comes into play because browsers see different versions as different files, and thus are foced to download the most recent version. So style.min.css?v=1.1 is a different file than style.min.css?v=1.2, and everyone is happy.

Using WordPress’s core enqueue functions will really make your site faster, and more standardized. Be sure to consider them for your next build.

Do you use wp_enqueue_style? Do you version your files and minify before you push live? What other techniques do you use to make your site more efficient?

1 Comment
  • Russell Heimlich

    Versioning static assets is a must when you are using a CDN. I wrote a handy little plugin that automatically timestamps CSS and JavaScript files that are enqueued.

    http://forrst.com/posts/CDN_Friendly_CSS_and_JS_URLs_in_WordPress-IZn

    Basically /main.css becomes /2011-08-03_7:01/main.css

    I had to do this because the CDN we are using at work is configured to pass any request with a query string (any URL with a ? in it) back to the origin server. Computers are good at keeping track of things like when a file is changed so it’s one less thing a developer like yourself should have to worry about.

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *