Hello Friends, Here is the most asked question across bloggers about WordPress Optimizations. Here we will do it with one plugin named “W3 Total Cache” which is already famous among bloggers, and Cloudflare, known for its optimization and security. At last, we will minify some unoptimized files manually. Here, with the combination of these three tools, we are going for WordPress Optimization.
Read: Best Tips To Boost Alexa Rank
Table of Contents
Steps for Performance Optimizations on WordPress
For Best Optimisations Result I will recommend you all to use Cloudflare along with W3 Total Cache with the settings that are specified below:-
Moving your DNS and Name Servers to Cloudflare
So, friends, this is the easiest and interesting step in this process.
Setting up WordPress Caching Mechanism
Setting Up W3 Total Cache
First, you have to install W3 Total Cache from the WordPress Repository. After this, the most preferred settings are illustrated with its state, i.e., Enabled or Disabled.
PS: WP Rocket is one of the best alternatives of W3 Total Cache as there are not of advanced configuration there(Everything is being already taken care of by the plugin team). It will be a straightforward setup.
Go to General Settings from the Performance tab in the WordPress admin panel.
- Toggle all caching types on or off:- Disabled.
- Page Cache:- Enabled.
- Page Cache Method:- Choose according to your hosting specification. (Default:- Disk Enhanced)
- Minify:- Disabled. (Due to disabling no further setting change in sub-items of minifying)
- Database Cache:- Enabled.
- Database Cache Method:- Choose according to your hosting specification. (Default:- Disk)
- Object Cache:- Disabled.
- Browser Cache:- Enabled.
- CDN:- Enable if you use any external CDN Service. (Default:- Disabled)
- Enable Varnish Cache Purging:- Disabled.
- Cloudflare:- Enabled. Enter Email Address that is registered with Cloudflare, Enter API Key and Domain without www.
- Security Level:- Medium.
- Rocket Loader:- Automatic. (Load All JavaScript Resources Async. i.e., Large Performance Boost )
- Minification :- HTML Only.(Safe)
- Development Mode:- Off.
- New Relic:- Enable if use New Relic. (Default:- Disabled)
- Miscellaneous: Verify rewrite rules:- Enabled.
Go to Page Cache from the Performance tab in the WordPress admin panel.
- Cache front page:- Enabled.
- Cache feeds: site, categories, tags, comments:- Enabled.
- Cache SSL (https) requests :- Disabled.
- Cache URIs with query string variables:- Disabled.
- Cache 404 (not found) pages:- Disabled.
- Cache requests only for www.*.com site address:- Enabled.
- Don’t cache pages for logged in users:- Enabled.
- Automatically prime the page cache:- Enabled.
- Update Interval:- 900 Seconds.
- Pages per interval:- As your server limit.(Default :- 15)
- Pre-load the post cache upon publish events:- Enabled.
- Leave other settings to default.
Go to Database Cache from the Performance tab in the WordPress admin panel.
- Don’t cache queries for logged in users:- Enabled.
- Maximum lifetime of cache objects:- 180000000 seconds.
- Garbage collection interval:- 360000000 seconds.
- Leave other settings to default.
Go to Browser Cache from the Performance tab in the WordPress admin panel.
General
- Set cache-control header:- Enabled.
- :- Disabled.
- Set W3 Total Cache header:- Enabled.
- :- Enabled.
- Prevent caching of objects after settings change:- Disabled.
- Disable cookies for static files:- Disabled.
- Do not process 404 errors for static objects with WordPress:- Disabled.
CSS & JS
- :- Enabled.
- Set expires header:- Enabled.
- Expires header lifetime:- 31536000 seconds.
- Set cache-control header:- Enabled.
- Cache-Control policy:- Cache with max-age.
- :- Disabled.
- Set W3 Total Cache header:- Enabled.
- Enable HTTP (gzip) compression :- Enabled.
- Prevent caching of objects after settings change:- Disabled.
- Disable cookies for static files:- Enabled.
HTML & XML
- :- Enabled.
- Set expires header:- Enabled.
- Expires header lifetime:- 3600 seconds.
- Set cache-control header:- Enabled.
- Cache-Control policy:- Cache with max-age.
- :- Disabled.
- Set W3 Total Cache header:- Enabled.
- :- Enabled.
Media & Other Files
- Set Last-Modified header:- Enabled.
- Set expires header:- Enabled.
- Expires header lifetime:- 31536000 seconds.
- Set cache-control header:- Enabled.
- Cache-Control policy:- Cache with max-age.
- :- Disabled.
- Set W3 Total Cache header:- Enabled.
- Enable HTTP (gzip) compression :- Enabled.
- Prevent caching of objects after settings change:- Disabled.
- Disable cookies for static files:- Disabled.
Leverage Browser Caching Using .htaccess (Alternative Method)
Warning: Before you start editing the .htaccess file, make sure to back it up; if something goes wrong, you can restore it to make your blog accessible again.
- The first step is to find your .htaccess file located in the root directory of your WordPress installation.
- Take a backup of your .htaccess file; if something goes wrong, you can replace the file to keep everything working.
- Open up .htaccess file.
- The first thing that you need to do is to get rid of Etag. After disabling Etag, a browser needs to rely on cache-control and expires header that is defined by you. For doing so, add the following code to your .htaccess file:
Header unset Pragma FileETag None Header unset ETag
- Now after disabling Etag. You need to specify expiry headers for the static content like CSS, JS, images, PDFs, etc. For that, add the following code:
## EXPIRES CACHING ## ExpiresActive On ExpiresByType image/jpg "access 1 year" ExpiresByType image/jpeg "access 1 year" ExpiresByType image/gif "access 1 year" ExpiresByType image/png "access 1 year" ExpiresByType text/css "access 1 month" ExpiresByType application/pdf "access 1 month" ExpiresByType text/x-javascript "access 1 month" ExpiresByType application/x-shockwave-flash "access 1 month" ExpiresByType image/x-icon "access 1 year" ExpiresDefault "access 2 days" ## EXPIRES CACHING ##
- Further, you can optimize the content delivery by compressing the components of your pages. For this to work, you need to have mod_deflate or mod_gzip installed on your hosting server. Now add the following code:
mod_deflate <FilesMatch "\\.(js|css|html|htm|php|xml)$"> SetOutputFilter DEFLATE </FilesMatch> mod_gzip <IfModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </IfModule>
- Now save your .htaccess file.
Optimizing JavaScript & CSS Manually
In this step, we will manually minify the JavaScript, which is not automatically optimized by W3 Total Cache And Cloudflare. You can also minify CSS using the same steps as below, but it can also break your theme so do it at your own risk.
Identifying and Minifying JavaScript/CSS using GTMetrix
- Go to GTmetrix.
- Analyze your blog.
- In Pagespeed, find Minify Javascript.
- Expand it. Now you have to see the location of that JavaScript file on your blog.
- Click the Optimised version to see the Optimised JavaScript File.
- Go to the file manager to the location of the JavaScript file. Click edit/code edit.
- Replace all the content with GTmetrix Optimised content.
- Click Save.
- Repeat this process for all other local JavaScript Files & do the same for CSS files.
Fix Render-Blocking JavaScript & CSS
- Go to WordPress Dashboard -> Performance -> General Settings.
- Change Minify mode to manual.
- Go to Google Pagespeed Insights and test your URL. Keep this page open we will need it later.
- Go to WordPress Dashboard -> Performance -> Minify.
- Navigate to JS section and enable it & change embed type of Before </head> to Non-blocking using “async”.
- Get the URL of the JS files that need to be fixed from the Google Pagespeed Insight test we did earlier.
- Now one by one, add those files as shown in the screenshot below.
- After adding all files, click Save all settings.
- Similarly, Enable CSS to minify settings.
- In CSS File management, follow the same process we did in JS above.
- After adding all files, click Save all settings.
- Now Empty all caches and recheck the Google PageSpeed Insights score.
Caution: Adding some JS/CSS files may cause a problem in loading or an undesirable user experience. So you can check after adding each file whether it is compatible with this optimization or not.
Deferring Parsing of JavaScript using Functions.php
Warning: Before you start editing the functions.php file of your theme, make sure to back it up; if something goes wrong, you can restore it to make your blog working.
- Open up the functions.php file in your theme folder either via hosting panel or WordPress editor.
- Add up the following code in the functions.php file.
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return "$url' async onload='myinit()";
}
add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );- Save your files and check your blog performance.
- In most cases, this works great, but if this is breaking your theme, you should remove the added code to revert.
Combine Images using CSS Sprites
- Open
SpriteMe(Discontinued) [Use this instead]. - After opening, you will see the installation section and drag that link to your bookmark toolbar. (It is actually JavaScript)
- Open up your blog in a browser.
- Click SpriteMe from the bookmark bar. You will find something like this.
- Find images that are needed to be optimized using GTmetrix.
- According to your requirement, drag and drop to include or not include an image.
- Finally, click make sprite.
- Sprite will be created within a few seconds, and click on the link to open the sprite and save it.
- Now click export CSS. I will advise you to save the sprited image on your server.
- Do the changes as illustrated by SpriteMe in your CSS file and replace the URL from SpriteMe with the URL of the file you have copied on your server.
- Now you have successfully combined images using CSS sprites.
Also Read: Best Managed WordPress Hosting That You Should Try
Comparison Between Before and After Optimisations




Thank you for reading this post, and keep connected to Tech Arrival to continue enjoying wonderful posts. Share your views about this post in the comment section below. If you are still having any query, throw it in the comment section.
If you find this post helpful, don’t hesitate to share this post on your social network. It will only take a moment, and also it is quite easy and helpful for others.
Many of the settings depend very much on server configuration. Though this is a way to go. Probably only Cloud flare can be a week point, sometimes Cloud flare instances would slow down loading instead of speeding it up.
You are right but this happens in very few case, but it is still a good option. You can also check out page speed of Tech Arrival.
Great post! You might be interested in testing https://www.dareboost.com !
Feedback would be great :)
DareBoost is optimised to best possible speed. Tested via Google PageSpeed Insights and GTmetrix.
ahah thanks :) My idea was to see you to test our tool that is similar to GTMetrix and Pingdom Tools, to have your feedback on it;)
Yeah. It is great.