Categories
Uncategorized

Optimize your website in 5 minutes

Getting a good score in Google Pagespeed Insights is very important, as it is a main factor for good User Experience (UX).

Minify Js, HTML & CSS

Minifying the Javascript, HTML and CSS helps reduce the page load times drastically.

Optimize Images

Optimize your images before hosting them online and using them on your site. You can optimize images online for free here.

Reduce Server Response Time

According to Google, the ideal server response time is less than 200 milli seconds.

  • Minimize plugins by removing unused plugins
  • Try to minimize the use of WordPress plugins that serve more than one purpose, like Yoast SEO which takes care of your SEO and also manages your sitemap.xml
  • Make sure that backup and caching is all performed on server side, instead of plugins.
  • Ensure that you have enough server capacity to balance your traffic.
  • Try to use server config files (Apache -> /etc/apache/apache.conf, Apache2 -> /etc/apache2/apache2.conf, nginx -> /etc/nginx/nginx.conf) for configuration rather than .htaccess files. The performance gain is negligible though.
  • Using HTTP 2 over 1. (You need an SSL certificate for this as HTTP 2 is dependent on HTTPS)
  • Use the Autoptimizeplugin to serve cached static Js and CSS content bundled into a single file.

Leverage Browser Caching

If you haven’t enabled the headers module in Apache, then enable them by running the following.

  a2enmod headers
  sudo service apache2 restart 

If you haven’t enabled the ExpiresDefault in your Apache. If you are using Ubunutu 14, it is a straight forward fix. You need to run the following line as root.
ln -s /etc/apache2/mods-available/expires.load /etc/apache2/mods-enabled/
You will need to add the following code to your server config file if using Apache. This code tells the browser for how long what filetypes are good, so that it doesn’t have to fetch them from the server everytime.


        ExpiresActive On
        # Set default expires to 2 days
        ExpiresDefault A172800
        ExpiresByType text/css A31536000
        ExpiresByType application/x-javascript A31536000
        ExpiresByType text/x-component A31536000
        ExpiresByType text/html A3600
        ExpiresByType text/richtext A3600
        ExpiresByType image/svg+xml A3600
        ExpiresByType text/plain A3600
        ExpiresByType text/xsd A3600
        ExpiresByType text/xsl A3600
        ExpiresByType text/xml A3600
        ExpiresByType video/asf A31536000
        ExpiresByType video/avi A31536000
        ExpiresByType image/bmp A31536000
        ExpiresByType application/java A31536000
        ExpiresByType video/divx A31536000
        ExpiresByType application/msword A31536000
        ExpiresByType application/vnd.ms-fontobject A31536000
        ExpiresByType application/x-msdownload A31536000
        ExpiresByType image/gif A31536000
        ExpiresByType application/x-gzip A31536000
        ExpiresByType image/x-icon A31536000
        ExpiresByType image/jpeg A31536000
        ExpiresByType application/vnd.ms-access A31536000
        ExpiresByType audio/midi A31536000
        ExpiresByType video/quicktime A31536000
        ExpiresByType audio/mpeg A31536000
        ExpiresByType video/mp4 A31536000
        ExpiresByType video/mpeg A31536000
        ExpiresByType application/vnd.ms-project A31536000
        ExpiresByType application/x-font-otf A31536000
        ExpiresByType application/vnd.oasis.opendocument.database A31536000
        ExpiresByType application/vnd.oasis.opendocument.chart A31536000
        ExpiresByType application/vnd.oasis.opendocument.formula A31536000
        ExpiresByType application/vnd.oasis.opendocument.graphics A31536000
        ExpiresByType application/vnd.oasis.opendocument.presentation A31536000
        ExpiresByType application/vnd.oasis.opendocument.spreadsheet A31536000
        ExpiresByType application/vnd.oasis.opendocument.text A31536000
        ExpiresByType audio/ogg A31536000
        ExpiresByType application/pdf A31536000
        ExpiresByType image/png A31536000
        ExpiresByType application/vnd.ms-powerpoint A31536000
        ExpiresByType audio/x-realaudio A31536000
        ExpiresByType image/svg+xml A31536000
        ExpiresByType application/x-shockwave-flash A31536000
        ExpiresByType application/x-tar A31536000
        ExpiresByType image/tiff A31536000
        ExpiresByType application/x-font-ttf A31536000
        ExpiresByType audio/wav A31536000
        ExpiresByType audio/wma A31536000
        ExpiresByType application/vnd.ms-write A31536000
        ExpiresByType application/vnd.ms-excel A31536000
        ExpiresByType application/zip A31536000
        ExpiresByType application/font-woff A31536000


# No caching for dynamic files

        ExpiresDefault A0
        Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
        Header set Pragma "no-cache"


# 1 MIN

        ExpiresDefault A60
        Header set Cache-Control "max-age=60, must-revalidate"


# 2 DAYS

        ExpiresDefault A172800
        Header set Cache-Control "max-age=172800, must-revalidate"


# 1 WEEK

        ExpiresDefault A604800
        Header set Cache-Control "max-age=604800, must-revalidate"


# 1 MONTH

        ExpiresDefault A2419200
        Header set Cache-Control "max-age=2419200, must-revalidate"

Now restart the service (sudo service apache2 restart)

Enable Compression

Add the following code to your config file for Apache to enable compression of the following file types.


       ...
       AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript

Avoid landing page redirects

Make sure that your homepage doesn’t have any redirects.

If you are using Google Adsense and Google Analytics or some external scripts like me, then it is up to you to decide whether to host these script files on your server or not.