Using a Caching System for Speed and Performance

A good way to improve the speed of your Web site is through caching different types of content. Caching content means to store it transparently so that it can be used for future loads of your Web site. A good caching system for your Web site collects all the Web pages on your site and copies, stores, and delivers the files to visitors of your Web site. This significantly reduces the server load because without it, WordPress creates pages on your Web site dynamically — each time a visitor loads your Web site, calls are made to the database and code is complied and executed each time to create the page in her browser. If you use a good caching program, those files are already built and displayed, so your Web server doesn't need to rebuild those pages each time.

The following are the different types of caching that can improve your site performance:

  • Page: Builds and stores (in your Web server memory) all the pages on your Web site. Page caches generally have an expiration date. In case you update content on your Web pages, the cache will eventually rebuild itself to capture changes you make.
  • Database: Reduces Web server overhead by storing and remembering database tables and queries made by WordPress.
  • Browser: Stores Web pages on the visitor's local storage so when she revisits your site, her browser displays the page from her hard drive memory, instead of rebuilding it and calling it from your server. Browser caches have an expiration date, so any changes you make can be captured again in the future (your site visitors can also set their browser settings to disable cache — so this may not work for everyone who visits your site).
  • Object: Stores data objects or HTML structures, which can increase server load because, without a caching system, they need to be rebuilt each time the site is loaded in a visitor's Web browser. Object caching helps the overall caching system by storing complete Web pages and saving them for future loads of your site.

Minifying JavaScript, CSS, and HTML

You can also improve the speed of your Web site through minifying — making some of the files, like JavaScript, CSS, and HTML, smaller. This involves taking all the files of your Web site and reducing the size by doing things like

  • Removing all line breaks and spaces in the file.
  • Removing all code comments in the file.
  • Removing unnecessary characters in the file.
  • Using code shorthand, where possible, to decrease the amount of characters in the file.
  • Combining the files into one file, wherever possible; therefore, instead of having ten JavaScript files, you could reduce the number to four or five.

Minifying JavaScript, CSS, and HTML files reduces the overall file size, making them load faster on your Web site. Obviously, adjusting each of the existing files on your site to make them smaller would take quite a lot of time and programming skills that you may or may not possess. Therefore, you may prefer to use a plugin or program to adjust these files. A good plugin or program used to minify files can reduce the file to 30–40 percent of its original size, which greatly improves the response time of your Web site.

Figure 5-2 shows the HTML source code from Lisa's Web site in its regular state, and Figure 5-3 displays it in a minified state. You can see how minifying shrinks the size of the overall file by removing spaces and line breaks, and shortening the characters used.

image Use a WordPress plugin (such as W3 Total Cache (http://wordpress.org/extend/plugins/w3-total-cache) that has a feature that minifies files, such as JavaScript, CSS, and HTML, by caching the minified files. This leaves the original files intact so they are easily readable and editable by you.

Figure 5-2: The HTML source code from Lisa's Web site.

image

Figure 5-3: The HTML source code from Lisa's Web site, minified.

image

Using a content delivery network

A content delivery network (CDN) stores your Web site data within different points on a network and can deliver that data to Web site visitors with a decreased amount of bandwidth. A CDN can choose to deliver this data from the nearest geographical location, making the transfer faster. Because of this, visitors don't access the data from the same place at the same time, which lightens the load on your server significantly.

To use a CDN, you need to sign up for a service that provides a network and a series of computers to store and serve your data on your Web site. The CDN can include items like images and CSS, JavaScript, and media files. Using a CDN reduces the load on your server because the files are delivered through the CDN, not through your Web server. This is especially helpful if you use a significant amount of bandwidth on your current hosting account.

CDN services are relatively inexpensive, particularly if you don't have a lot of media files, images, and data to store on their servers. A few popular CDN providers include

The benefits of running a content delivery network include the following:

  • Improved speed of your Web site
  • Improved visitor experience
  • Improved scalability for your Web site and database data delivery
  • Resistant to Web site crashes during times of high traffic volumes

image In the next section of this chapter, we give you a couple of plugins that provide a user interface to help you set up a CDN on your Web site. Just remember that CDN services aren't free, and the costs vary depending on the service provider that you use.

Using plugins to make caching easier

We recommend these two plugins, which provide you with the best and easiest ways to make sure that your WordPress site has a caching system in place:

  • W3 Total Cache: Install this plugin to easily optimize your Web site and user experience with page, browser, database, and object caching. W3 Total Cache also includes features like HTML, CSS, and JavaScript minify, as well as CDN configurations to improve your Web site's speed and performance (http://wordpress.org/extend/plugins/w3-total-cache).
  • WP Super Cache: This plugin generates static HTML files from your dynamic WordPress blog posts and pages. The static HTML files are then served to your Web site visitors instead of the dynamically generated PHP files, without affecting the look or function of your site. This reduces the load on your server and increases the speed of your Web site. Unlike the W3 Total Cache plugin, WP Super Cache (http://wordpress.org/extend/plugins/wp-super-cache) doesn't have minify or CDN configurations.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.95.216