Connect with us

PERFORMANCE

Speed Up WordPress Performance with htaccess

Published

on

Till now we have discovered a lot of speed up WordPress performance without code here. Further, we had learned speed up WordPress with code improvement and database optimization tips. The last thing we can do to speed up WordPress performance is, put few lines of code in the .htaccess.

Having a better-configured server loads your website much faster. Hence, we’re going to tell you the things which you can easily implement on your server to process requests faster. In contrast, just a basic understanding of PHP, MySQL and FTP client is inevitable from you here again.

Speed Up WordPress Performance

There are three things you can do and instruct your server engine for optimum performance. They are:

Enable gzip compression
Expires Header to Static Resources
Disable hotlinking and leaching of content

We’re explaining each of those in details here and those will ultimately speed up WordPress performance for your website and visitors.

1. Enable Gzip Compression

The more you will compress your resources, the lesser the loading time will be. Again, compression means making your files smaller and thus faster to download. In addition, all modern browsers can interpret compressed files so it’s an excellent option to enhance WordPress performance.

If you’re using a caching plugin then high chances are the compression code has been already added to your server. Alternatively, you can add the following lines of code in the .htaccess file on your server. The .htaccess file is usually found in the root directory of your website. Moreover, it stays hidden or invisible by default.

You can display it by choosing “show hidden files” or similar option from the menu in your FTP client. You need to edit the file and save the following code to the end of it. The code is taken from GTmetrix.

<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml

# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>

Check WordPress Performance with Gzip Compression

Enabling Gzip Compression is another potentially huge speed gain too. Again repeating that the server would already be serving zipped assets if you’re using caching. You can verify that also by inspecting the .htaccess file.

You can also verify Gzip Compression using tools described in our blog post or at check compression website here. On the other hand, note that using gzip on images won’t provide any additional benefit to WordPress performance. Rather, use Image Optimization as described here.

2. Add an Expires Header to Static Resources

An expires header is a way to tell the browser to cache static content for the specific time. In this way, the client browser doesn’t need to re-fetch static content like images, JS and CSS from the server in each request. So you can significantly improve WordPress performance or speed for regular users or subsequent requests using expires header.

Check out this GTmetrix article to understand how does Expires Header works and how to add. Also, your caching plugin might have already implemented this feature. Further, set expires header carefully as you have the need to take care if content changes before the expiry duration.

3. Disable Hotlinking and Leaching of Content

Disabling hotlinks and leaching don’t directly speed up your website. But it protects unnecessary loads on your server, hence participates in faster speed to serve the purposeful traffic. Hotlinking is a practice to display content like an image from a website to another by linking that directly from the first one.

Suppose an image is hosted on your website. Website B shows the image by placing the image URL from your website, rather than uploading it to own server. Thus, content is served by effectively stealing bandwidth of your site and you’re not getting any traffic/advantage.

While your server is already busy serving genuine requests, the hotlinking imposed burden on it. So your site will suffer poor performance due to this leaching of content. Simply add this code to your .htaccess file to block hotlinking of images from your WordPress site.

#disable hotlinking of images
RewriteEngine on
RewriteCond {136ce94cc7fec1f5657bab0b4d73ed308318c1024f899c463e79e42d4b375fbf}{HTTP_REFERER} !^$
RewriteCond {136ce94cc7fec1f5657bab0b4d73ed308318c1024f899c463e79e42d4b375fbf}{HTTP_REFERER} !^http(s)?://(www\.)?rella.com [NC]
RewriteCond {136ce94cc7fec1f5657bab0b4d73ed308318c1024f899c463e79e42d4b375fbf}{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteCond {136ce94cc7fec1f5657bab0b4d73ed308318c1024f899c463e79e42d4b375fbf}{HTTP_REFERER} !^http(s)?://(www\.)?feeds2.feedburner.com/rella [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L]

Just replace rella.com with your own domain. You also need to replace our feed (from FeedBurner) to your feed as well. Finally, you have done to disable hotlinking and leaching of content.

WordPress Performance – Check Website Speed

Well! We’re doing our best efforts to achieve the highest performance of the WordPress website. But still is there any tool which can analyze the performance of the website? Further, that can show us broad analysis along with the resources and requests which are making site slower? Is there any tool that can check website speed and WordPress performance?

Indeed, there are. We have written an excellent article which tells you about 5 cool tools to check website speed. It also covers tools for WordPress benchmarking. Not to mention, you must read the article as given in link and test how is your site performing. Also, modify any resource/request that is causing slow performance with help of the data shown by the tool.

Remember: Speed isn’t Everything

So far we have learned the most effective tips to speed up WordPress. In the first place, we improved WordPress performance with 12 tips that require only some installation and selection. Then we learned to speed up WordPress with code and database optimization. And at last here, instructed the server through the .htaccess file to speed up the WordPress performance.

We are also able to check the speed of our site and update it using the data provided by speed checking tools. So while we have focused on the speed and performance of WordPress, know that speed isn’t that everything. Rather than the maximum speed, focus on the reasonable performance.

Consider wisely if you need to reduce page load time to 100 ms at the cost of $500 monthly or additional time. Would it really serve any purpose other than a crazy speed? Also, a visually appealing and user-friendly website usually means making a compromise in other areas. But it’s a must.

Additionally, the outcome will reduce along with the increasing implementation of the tips. It means like from 5 seconds to 2.5 seconds speed boost with the first 5 tips. Then from 2.5 seconds to 1.5 seconds loading from next 15-20 more tips. This is usual.

Security and Search Engine Optimization (SEO) are also equally as important as performance. So attend optimum with proper balancing among tools, money, time, complexity and resources. It’s better to get website speed from 4.5ms to 1.5ms. And if lowering it is worth to you then put in more efforts.

WordPress Performance – Final Thought to Speed Up

You can take the most of WordPress speed leverage through:

Choosing a good host and an optimized theme like Boo
Utilizing a caching plugin and image optimization
Files minification and database optimization

So using the tips above, you can bring quite faster loading as the most of users seek. Further, you would need more if you have popular or heavy traffic website or just if you wish. After all, you can get more speed through the tips described in all these three articles about WordPress performance.

Share us your experience as well as the success story from these articles. If you have any questions, comments, ideas or tested methods, also let us know in the comments below. We’d love to hear from you especially!

Continue Reading
Click to comment

Leave a Reply

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

Trending