Website Speed Optimization

Website Speed Optimization – 3 to 1 second in no time! Do it Free!

WordPress is a fabulous platform. The only thing that WordPress doesn’t cover for a hundred percent is the speed, yes, might be pretty slow.

If there’s no action for this matter, you will end up with a slow website that Google doesn’t prioritze due to the speed report( The Website Speed Optimization Matters!)

Today, we are going to speed your wordpress website from 3 to 1 second in no time at all. Curious? Well, let’s hit that!

The Website speed optimization is crucial!

At the moment someone comes into your site, there’s an interval of time you got to captivate the user, perhaps, a few seconds only. If the waiting time goes over the user’s patience, you lost it! That’s how important the loading time is.

Before we start, please have these in consideration:

  • The host. (Most of the times isn’t an issue, though, you gotta be careful)
  • Pick an optimized Theme for your site.
  • The CDN
  • Caching Plugins(We’ll go through with this)
  • Image Optimization
  • Expires Headers
  • Http Requests

So, enough for a short introduction – Let’s get to the point where we actually do website speed optimization.

For this Tutorial, we’ve picked a website and this is the shape it was in at the first look:

Website Speed Optimization
Start point 1
Start Point
Start Point 2
Start point 2
Start Point 3

Pretty critical, right? This speed will never bring any benefits! Either Google or just the users will get bored waiting.

First step in optimizing the website.

Wp Rocket:

We would HIGHLY recommend that you’d use Wp Rocket as a caching plugin due to its killing instincts when it comes to Slowness.

We won’t cover a Wp Rocket Settings Configuration in this Tutorial because you need to find the suitable settings for your site!

Second step.

Cloudflare:

Probably many of you already heard of Cloudflare and how recommended it is as a CDN(Content Delivery Network). There are other CDNs, of course, you can choose.

Website speed optimization – Prefetch DNS requests

Latency can be dramatically reduced by setting up DNS Lookups performing in the backround with DNS prefetching.

You can use https://prefetch.xyz/ to make sure where your site sends requests(In case it fails, it happens, here’s a list to compare to your site and use what you are needing)

//maps.googleapis.com
//maps.gstatic.com
//fonts.googleapis.com
//fonts.gstatic.com
//ajax.googleapis.com
//apis.google.com
//google-analytics.com
//www.google-analytics.com
//ssl.google-analytics.com
//youtube.com
//api.pinterest.com
//cdnjs.cloudflare.com
//pixel.wp.com
//connect.facebook.net
//platform.twitter.com
//syndication.twitter.com
//platform.instagram.com
//disqus.com
//sitename.disqus.com
//s7.addthis.com
//platform.linkedin.com
//w.sharethis.com
//s0.wp.com
//s1.wp.com
//s2.wp.com
//s.gravatar.com
//stats.wp.com
//www.googletagmanager.com
//www.googletagservices.com
//adservice.google.com
//pagead2.googlesyndication.com
//tpc.googlesyndication.com
//bp.blogspot.com
//1.bp.blogspot.com
//2.bp.blogspot.com
//3.bp.blogspot.com
//4.bp.blogspot.com
//ajax.microsoft.com
//ajax.aspnetcdn.com
//s3.amazonaws.com
//code.jquery.com
//stackpath.bootstrapcdn.com
//use.fontawesome.com
//player.vimeo.com
//github.githubassets.com
//referrer.disqus.com
//c.disquscdn.com
//0.gravatar.com
//2.gravatar.com
//1.gravatar.com
//ad.doubleclick.net
//googleads.g.doubleclick.net
//stats.g.doubleclick.net
//cm.g.doubleclick.net
//stats.buysellads.com
//s3.buysellads.com
//fonts.googleapis.com/

Open DevTools (F12 On chrome) Refresh your browser, almost every single request will be visible.

The website score is also affected by the images – The bigger in size, the more “evil” to your site. Trust me, you don’t want that!

Imagify – Imagify is a plugin that compresses and convert your images, it’s a pretty crazy one! If you don’t want the plugin, you can just go to imagify.io and optimize each of them before uploading.

Cookie-Free Domain – Serve Static Content from a subdomain

Let’s start with the cPanel (aka subdomain creation)

1. Go to your cPanel > Subdomains > Create a Subdomain
2. I will name the subdomain as “optimize” (optimize.website.tld)
3. Change Document Root to public_html/wp-content
4. if you are using Cloudflare go to your Cloudflare dashboard and add new record A, name it static and point it to your IP.

Cloudflare
Cloudflare

5. Start looking for wp-config.php and write in the following lines:

/** Cookie-Free Domain. */
define("WP_CONTENT_URL", "https://optimize.website.tld");
define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] );

Make sure to change “optimize.website.tld” to your domain name!

6. Now you must redirect all the posts to the new subdomain. Simply, run the following command in the SQL Database via phpMyAdmin.

UPDATE wp_posts SET guid = REPLACE(guid,'website.tld/wp-content/','optimize.website.tld/')
UPDATE wp_posts SET post_content = REPLACE(post_content,'website.tld/wp-content/','optimize.website.tld/')

7. After you are done with all of these steps, refresh your page. Check for errors!

EXPECTED ERROR: Problem loading web fonts, FontAwesome, etc. due to CORS policies

8. (Fix) I’m using RankMath for this one. But you can fix it with any other plugin for this matter.

Go to your .httaccess file and add the following on the top line.

#CORS FIX
<IfModule mod_headers.c>
 <IfModule mod_rewrite.c>
    SetEnvIf Origin "http(s)?://(.+\.)?(optimize.website\.com|website\.com)(:\d{1,5})?$" CORS=$0
    Header set Access-Control-Allow-Origin "%{CORS}e" env=CORS
    Header merge  Vary "Origin"
 </IfModule>
</IfModule>
#CORS FIX END

READ: Change “website” to your domain name and “.com” to your own TLD.

– Prevent Contact Form 7 from loading on every page.

This happens many times, even though, there’s no actual reason for it. It will not be on every WordPress Installations – 3 out of 5 can have it.

1. Navigate to functions.php (public_html/wp-includes)
2. Add the following code at the bottom.

// Remove contact form 7
add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );
add_action('wp_enqueue_scripts', 'load_wpcf7_scripts');
function load_wpcf7_scripts() {
  if ( is_page('contact') ) {
    if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
      wpcf7_enqueue_scripts();
    }
    if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
      wpcf7_enqueue_styles();
    }
  }
}

If you have CF7 on multiple pages, change ” if ( is_page(‘contact’) ) {” to “if ( is_page(‘contact|page1|page2|page3’) ) {“

– Remove version entirely from the source file
WPRocket will usually do the job with this, but if you have CSS/JS files that are excluded WPRocket won’t touch them in any way, so this one is coming in handy to those files.
1. Go to functions.php (public_html/wp-includes)
2. Add the following code at the bottom.

// Remove version entirely from the source files
function sh_remove_ver_css_js( $src_file ) {
    if ( strpos( $src_file, 'ver=' ) )
        $src_file = remove_query_arg( 'ver', $src_file );
    return $src_file;
}
add_filter( 'style_loader_src', 'sh_remove_ver_css_js', 9999 );
add_filter( 'script_loader_src', 'sh_remove_ver_css_js', 9999 );

This is the website speed optimization most of the “agencies” charge you at least 100$. Pretty cool and easy, right?

Here are the results after the website speed optimization:

Website speed optimization
End point 1
End point
End point 2
End point 3
End point 3

That’s all! You should now have an optimized website – Website Speed Optimization was never easier!

Note: With a fast Website come a lot of benetfits. Make sure to do your website speed optimization A-Z!

Useful Links:

Leave a Comment

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

Scroll to Top