Tutorial: How to Optimize WordPress Website Performance

in website •  8 years ago  (edited)

This is my first post on Steemit platform. Here I would try to explain you how to optimize your WordPress website performance, so it can be rendered faster by the browser. From the start of this year, I had optimized more that 20 WordPress websites, so I have some experience in this field :)

Let's start!

Most popular web application for testing website performance are:  PageSpeed Insights and GTmetrix.

Most of people who are using WordPress are not familiar with HTML/CSS, JavaScript and/or PHP. Because of that, they use plugins for almost anything. There are a lot of plugins for WordPress, some of them are good,  other don't.

Before we start make sure that you have a backup of your website and delete every plugin that is not necessary for your website. Many plugins will add some tables  in the database and some code into HTML document. That code will be added when a browser request webpage from the server.

# Reduce number of HTTP requests

The point is that you need to decrease web page size and number of requests, so it can be downloaded faster.

Request are very important. Ideally you would have only one HTTP request and that will be requested for HTML document. Of course, it's almost not possible on modern websites, but you should keep them at a minimum.

As I mentioned above, plugins add extra code into your HTML document. That code is usually external CSS and JavaScript files. When the browser start crawling your HTML document, it will go from top to bottom. Whenever a browser finds the external CSS or JavaScript file, it will stop rendering of page until these files are not fully loaded. That is called render blocking. Render blocking is related to HTML, CSS and JavaScript files. Images doesn't block rendering of webpages.

To reduce number of requests and decrease size of HTML, CSS and JavaScript files, I like to use ,,Autoptimize" plugin. This plugin will compress (remove unnecessary empty space from HTML, CSS and JavaScript) and combine CSS and JavaScript files to reduce the number of requests.

After you install that plugin, you should change some settings there. Click on ,, Show advanced settings".

You will be on screen like this:

HTML will not make any problem.

Sometimes it may happen that your JavaScript file break after compression. If that is the case, you can exclude file that makes you problem or uncheck JavaScript optimization.

When it comes to CSS, in 90% it works fine. If there is some problem, it's usually related to the style.css file (in your theme folder) or you would need to uncheck ,, Also aggregate inline CSS?" option.

# gZip compression and Browser Caching

In WordPress "world", most popular plugin to do this is "W3 Total Cache", but we can enable gzip and caching without the use of any plugin.

To enable that, you would need FTP or cPanel access, so you can modify .htaccess file. That file is located in the root directory of your website. Usually under public_html or www. In that folder you will find your website and .htaccess file.

When you open that file, there will be some code.

At the bottom (in my case after # END WordPress), you should write code that will enable gzip and browser caching.

# EXPIRES CACHING

<IfModule mod_expires.c>

ExpiresActive On

ExpiresByType image/jpg "access 1 month"

ExpiresByType image/jpeg "access 1 month"

ExpiresByType image/gif "access 1 month"

ExpiresByType image/png "access 1 month"

ExpiresByType text/css "access 1 month"

ExpiresByType application/pdf "access 1 month"

ExpiresByType application/javascript "access 1 month"

ExpiresByType application/x-javascript "access 1 month"

ExpiresByType application/x-shockwave-flash "access 1 month"

ExpiresByType image/x-icon "access 1 month"

ExpiresDefault "access 2 days"

</IfModule>

# END EXPIRES CACHING

This will enable browser caching and it will decrease page loading time and the number of HTTP request for second time visitors. When someone visits your website, static resources (images, CSS and JavaScript) files will be saved on the visitor's computer. If that person visit your website again or some other page on your website, the browser will first look to see if some external file is saved in the computer. If the answer is yes, it will not send request to server for that file, instead it will take it from the visitor's computer.

Now let's enable gzip compression.

This is for Apache web servers only, for NGINX servers, settings are different.

Bellow code for caching that we added, you would need to insert a few lines of code that will enable gzip compression. Gzip is important because it will drastically decrease the size of text files (HTML, CSS and JavaScript). Code that you would need to add is:

# Gzip

AddOutputFilterByType DEFLATE text/plain

AddOutputFilterByType DEFLATE text/html

AddOutputFilterByType DEFLATE text/xml

AddOutputFilterByType DEFLATE text/css

AddOutputFilterByType DEFLATE application/xml

AddOutputFilterByType DEFLATE application/xhtml+xml

AddOutputFilterByType DEFLATE application/rss+xml

AddOutputFilterByType DEFLATE application/javascript

AddOutputFilterByType DEFLATE application/x-javascript

# END Gzip

Now my .htaccess file looks like this:

# Image optimization

It is always good to optimize your images before uploading them to the server, but don't worry if you didn't ;) There are a lot of good plugins that can help you with this. One of the most popular plugins for this is "WP Smush". My suggestion is that if you are using some plugin to optimize images, you should disable it after image optimization is finished. Why? Because you should keep the number of active plugins to a minimum.

If you want to optimize your images manually or before uploading to the server, I highly recommend the Optimizilla web application.

To manually optimize images, you would need to navigate to your website folder (like we do for gzip and caching). There you will see wp-content folder and inside of it uploads folder. In that folder are located all of your media files. You can download them and after optimization, upload it again.

If you are using Optimizilla you would also need to rename optimized files, because that web application adds "-min" at the end of optimized file. You would need to remove that in order to override the original file on the server.

This is some basic steps that you would need to take in order to make your website faster. I hope that this tutorial will help someone and sorry for my bad English.

Have a good day!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you @slavko993, for your post on optimizing WordPress. Your post has helped alot.

I have not heard of Optimizilla before and will start using it.

I also liked the tip about adding the GZIP and Browser caching in the .htaccess file. I typically use a plugin for that.

Thanks again and I look forward to learning more WordPress tips from you.

Thanks! I'm glad to hear that and I would definitely wrote more about WP.

Everything you can, you sould do without plugin. Optimizilla is great website and I use it constantly.

Best regards!

Ovaj post je zasluzio vise upvote-ova!

Hvala! Ovde sam se molo raspisao. Mozda sam trebao da promovisem ovaj post ili stavim u neku drugu kategoriju.

Hej cao . Koju si strategiju prihvatio - sta mislis da je najbolje za promociju postova? Takodje, sta mislis i o nekom ne nuzno srpskom, nego recimo ex-yu tagu. Ako bi on postojao mogli bi svi iz regiona da se povezemo preko njega i da pisemo na maternjem. To mi zvuci ok. Tridesetak miliona ljudi ukljucujuci dijasporu. Samo pitanje je kolko ih zna za steemit. Ok, necu sad da zaludjujem. Samo napred. Ziveli!

Zdravo!

Nemam nikakvu strategiju. Sada se trudim da pisem o kripto valutama, uglavnom kratke postove. Nikako da se nakanem ali bilo bi najbolje kada bi mogao da izbacujem po tri posta dnevno, samo da nakupim pratioce.

Mislim da nas ovde nema dovoljnjo ako se pogleda ,,ex YU" trziste. Sigurno ce nas biti sve vise kako ova platforma bude rasla. Tako da ce onda biti smisla pisati na matenjem jeziku.

Sve najbolje!