How to make your website load faster like a pro?

You can find many tutorials about making your website faster. Most of them are not involving technical skills and are superficial. I will show You the proper technical way to achieve better results with fewer, but more advanced steps.

We will look at DNS and web server configuration, so You need little technical skills and have your own VPS (Virtual Private Server) for a few steps.

Cloudflare

Have You heard about it? You definitely should, fantastic tool.

In my opinion, it’s the easiest and the most important thing that You can do to speed up your website a few times. Cloudflare provides Firewall, DDoS protection, intelligent routing, mobile & image optimization, cache, and the most important function – the fastest DNS resolver.

Let’s look at how it helped with the speed of my biggest website:

Impressive, isn’t it? Below You can find steps to reproduce my configuration:

  1. Create an account on Cloudflare
  2. Change your DNS record to Cloudflare nameservers
  3. Go to the „Speed” section in dashboard and „Optimization” tab
    – check JavaScript, CSS, and HTML in „Auto Minify”
    – turn on „Brotli”
    – on some pages, you can turn on „Rocket Loader” if it’s don’t messing up with your Java Script (on WordPress I’ve turned this off)
  4. Go to the „Caching” section in dashboard
    – set „Caching Level” to standard
    – set „Browser Cache TTL”, I’ve set it to 1 month, You can go shorter if You want
    – turn on „Always Online”
  5. Go to the „Network” section in dashboard
    – turn on „HTTP/3”
    – turn on „0-RTT Connection Resumption”
    – turn on „WebSockets”
    – turn on „Pseudo IPv4”
    – turn on „IP Geolocation”

Apache MPM-event

From this part You need your own VPS (Virtual Private Server) to configure everything exactly as You want. I’m familiar with the Apache web server, so this tip is only useful for this solution. Changing your MPM (Multi-Processing Module) is a significant factor to speed up your website loading times.

Prefork

Default MPM in Apache is prefork, that’s a non-threaded, pre-forking web server. That means each child process contains a single thread and handles one request at a time. You can easily deduce, it consumes more resources than the threaded MPM.

Event

In my opinion the best MPM you could choose is the event. It also contains multiple threads, but each of them is capable of more than one task at a time. This results in fewer resources requirements. Other benefits are a bigger transaction rate per second and throughput.

Apache with this MPM is as fast as Nginx. True story :)

I’ve got for you two event configurations. This is speed one:

<IfModule event.c>
  ServerLimit 16
  MaxClients 400
  StartServers 3
  ThreadsPerChild 25
  ThreadLimit 64
</IfModule>

and that is an economical one:

<IfModule event.c>
  ServerLimit 8 
  MaxClients 200 
  StartServers 3 
  ThreadsPerChild 25
  ThreadLimit 64
</IfModule>

PHP-FPM

PHP-FPM is the implementation of a PHP interpreter with some additional clever features useful for heavy websites. This technology cache queries on the server-side, so when the same query will be needed FPM will use cached one. That optimization helps lower average load on the server and speed up your sites/scripts.

The installation guide for your Linux distribution is easily findable, so I will quickly jump to configuration. You can find below my recommended settings for 4GB RAM web servers:

/etc/php/7.4/fpm/pool.d/www.conf

pm = dynamic
pm.max_children = 120
pm.start_servers = 12
pm.min_spare_servers = 6
pm.max_spare_servers = 18

PHP Memory limit

Also one of the key aspects that should be considered and it’s connected with the speed of your site is PHP memory limit. I’ve got a very high 1GB memory limit, but 256MB will be fine. That setting will also apply to the nonPHP-FPM configurations but needs to be changed in a config file placed in a different location.

/etc/php/7.4/fpm/php.ini

memory_limit = 1024M

Summary

I’m certain that applying the above three steps to your site and web server configuration will result in a significant speedup in loading sites.

If You know any other tips and tricks that will help in load times let me know in the comment section.

PS. Bonus Cloudflare security settings

  1. Go to the „SSL/TLS” section in dashboard
    Set encryption based on your site properties:
    – if You haven’t got SSL certificate and You won’t have set „Flexible”
    – if You are a more advanced user set Full (strict) setting – my choice, but You need to configure SSL with Cloudflare Origin CA on your server or You have an existing certificate provided by different CA.

    Next change these options in the „Edge Certificates” section:
    – „Always Use HTTPS”
    – „Opportunistic Encryption”
    – „TLS 1.3”
    – „Automatic HTTPS Rewrites”
  2. Go to the „Scrape Shield” section in dashboard
    – turn on „Email Address Obfuscation”
    – turn on „Server-side Excludes”
    – turn on „Hotlink Protection”
  3. Go to the „Page Rules” section in dashboard
    To ensure that all traffic goes over secure https connection You can add simple page rule:


Join my Newsletter! 👨‍💻

Subscribe to get my latest content by email 🦾

Also read...

The best entries...