Updated on Dec 6, 2022
Sometimes you might be not satisfied with the loading speed of your WordPress based website which can be a result from bad server-side optimization or from large amount of elements being loaded on your pages. In such cases there are few useful “tweaks” you can use to speed up the loading time of your website.
This tutorial will provide you with detailed information on the possible optimizations you can perform without contacting your hosting provider or without installing any additional services.
First we will begin with Gzip File Compression. This type of optimization will cause the response time of your website on the client’s browser to be reduced by reducing the size of the content sent to the client.
In order to activate the compression layer you will need to add the following line into the .htaccess file of your website:
Once these lines are added and you refresh your website you will clearly notice the difference in the loading speed which will be more than enough.
Secondly we will proceed with some configuration for the ETags mechanism. This mechanism servers for client browsers to determinate if the component they have cached is matching the same component on the original server. If these are disabled this check will be terminated and the loading speed will be increased.
In order to disable them you will need to add the following lines in the .htaccess file for your website:
Header unset ETag FileETag None
The final step will be for a configuration for the browser’s cache to be added again to the .htaccess file of your website.
Browser caching is used for you to specify the exact time client browser should cache contents from your website and after this time expires for the cache to be renewed.
Once a client makes a request for accessing your website in, his/her browser will attempt to download the static elements of your website and also the result of the php execution each time the visitor access pages on your website. By adding the bellow provided lines you will enable the Expires and Cache-Control headers so the files which your visitor are downloading each time to remain on his computer so the browser cannot redownload them each time the visitor browse a page on your website.
Mod_headers is controlling the HTTP request and response headers.
# BEGIN Cache-Control Headers <ifModule mod_headers.c> <filesMatch "\.(ico|jpe?g|png|gif|swf)$"> Header set Cache-Control "public" </filesMatch> <filesMatch "\.(css)$"> Header set Cache-Control "public" </filesMatch> <filesMatch "\.(js)$"> Header set Cache-Control "private" </filesMatch> <filesMatch "\.(x?html?|php)$"> Header set Cache-Control "private, must-revalidate" </filesMatch> </ifModule> # END Cache-Control Headers
With these changes in the .htaccess file for your website you might drop the loading time of your website with up to 80% especially if your website uses large amount of static components.
Congratulations! You have successfully optimized the loading speed of your website!