How to optimize website performance

This article describes steps you can take to help optimize your website's performance.

This article provides general performance recommendations for a website. If you are using one of the following popular web applications instead, please see its related article for specific performance recommendations:

Optimizing website performance

The following sections describe steps you can take to help boost your website's performance. These recommendations are not all-or-nothing—you can follow some of the recommendations, and still realize performance benefits. Usually, however, the more optimizations you enable, the greater the performance increase.

If you configure the settings as described below and your site's performance is still not at the level you want, there are additional options:

Compression

You can add Apache mod_deflate directives to the .htaccess file in your web application's root directory to compress output. Compression saves bandwidth and ensures faster page download times.

To enable output compression for your web application, follow these steps:

  1. Using your preferred text editor, open or create the .htaccess file in the directory where you installed your application.
  2. Add the following lines to the .htaccess file:
    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript
    </IfModule>
    
    This configuration provides a basic set of rules for compressing content (HTML, CSS, and JavaScript). You should consult the documentation for your own web application for any additional content types that can be compressed.
  3. Save your changes to the .htaccess file. The changes take effect immediately.
Browser caching

The Apache mod_expires module enables you to instruct client web browsers how long to cache certain types of content. This both saves bandwidth and ensures faster page download times. To enable browser caching directives for your site, follow these steps:

  1. Using your preferred text editor, open or create the .htaccess file in the directory where you installed your application.
  2. Add the following lines to the .htaccess file:
    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType image/gif "access plus 1 month"
        ExpiresByType image/jpeg "access plus 1 month"
        ExpiresByType image/png "access plus 1 month"
        ExpiresByType text/css "access plus 1 week"
        ExpiresByType text/javascript "access plus 1 week"
        ExpiresByType application/javascript "access plus 1 week"
        ExpiresDefault "access plus 1 week"
    </IfModule>
    
    This configuration provides a basic set of rules for caching commonly-used content types. You should consult the documentation for your own web application for any additional content types that can be cached.
  3. Save your changes to the .htaccess file. The changes take effect immediately.
Minify and combine JavaScript and CSS files

To help decrease page load times and improve performance, you can combine and minify JavaScript and CSS files.

By combining these files into a smaller number of files, you reduce the number of HTTP connections necessary to load your site.

By minifying these files, you reduce the amount of bandwidth required to load your site. The minification process involves removing all unnecessary characters (such as whitespace and comments) from the source files. There are numerous online sites that minify files, for example:

Optimize image files

Optimizing your image files is one the best (and easiest) ways to improve site performance. For detailed information about how to optimize image files for your site, please see this article.

Server caching

If your hosting package supports it, you may want to use caching at the server level. There are a few ways to do this:

  • APC: The Alternative PHP Cache (APC) is a PHP extension that provides opcode caching. By caching the compiled operation codes (opcodes) of PHP scripts, APC enables sites to serve page content significantly faster. APC runs on PHP 5.4 and earlier versions.
    Because APC is a separate extension, it may or may not already be installed on your server. To determine if your server has the APC extension installed, please see this article.
  • OPcache: On PHP 5.5 and later versions, OPcache replaces APC. OPcache is a core PHP component that does not require installing a separate extension.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.