Optimize Cloudflare
Tags: cloudflare, optimize, dns, performance
Published: 2020-06-16 22:35:46

<h3>What is Cloudflare?</h3>
I used to share the misconception that Cloudflare was simply a CDN (Content Delivery Network) service during the early stages of my web-dev career. However, I made the switch to Cloudflare to manage my domains after learning that it is more than just a CDN, but also provides many security and performance benefits. Each time that I purchase a new domain and hosting plan, I'm able to connect the two with Cloudflare in a matter of minutes. Although Cloudflare provides many different features, I will solely focus on a few settings that enhanced my websites via DNS Management.
<h3>Getting Started</h3>
The first step is to an account. If you already have updated your nameservers to match Cloudflare then skip this section.<br>
1) Register a <a href="https://dash.cloudflare.com/sign-up">Cloudflare Account</a>
2) Enter your website name.
3) Select "Free" Plan
4) Review your DNS settings.
5) Follow the <b>Change your nameservers</b> instructions. This typically entails logging in to your domain provider (i.e. GoDaddy). Edit DNS settings and update nameservers.
```Example nameservers:
NS aldo.ns.cloudflare.com
NS josephine.ns.cloudflare.com```
You can now check to see if your nameservers are properly configured on Cloudflare. I recommend waiting at least 5-10 minutes for it to update.<br>
6) Update the target value (content) to point to your webhost. If you're using <a href="https://heroku.com">Heroku</a>, they will grant you a value to add, ie clear-stonecrop-1r783irsddna.herokudns.com

<img src="https://dev-to-uploads.s3.amazonaws.com/i/ouqchsv01x1s0sekmbeu.png">

<h3>Page Rules</h3>
Now that you have successfully connected Cloudflare, let's change a few things on the page rules tab. The free plan will allow up to three rules.<br>
<b>Rule #1</b>
```
*YOURDOMAIN.com/*
Always Use HTTPS 
```
Cloudflare provides free SSL certification (https), so let's use it and get that neat lock icon to appear next to our domain name.<br>
<b>Rule #2</b>
```
YOURDOMAIN.com/*
• Auto-minify Html, Css, Js
• Rocket Loader On
• Browser Cache TTL - 1 month
```
Minifying our code will help with load times. Browser Cache will help reduce resources for returning visitors. Rocket Loader will prioritize your website's content by deferring the loading of all of your JavaScript until after rendering, so users won't have to wait when visiting your site.<br>
<b>Rule #3 (Optional)</b>
```
www.YOURDOMAIN.com/*
Forwarding URL - 301 Permanent Redirect
https://YOURDOMAIN.com/$1
```
You will not be required to set up any redirects. I personally don't like my sites being accessed with the "www" sub-domain so I've setup this redirect to my homepage in case anyone prepends the domain URL with "www".

<b>Note:</b> The reason that why we use an asterisk (*) is to create dynamic patterns that can match many URLs, rather than just one.

<h3>Caching</h3>
Below the caching configuration, we can manually purge cache, set global rules, and switch to <b>Development</b> mode to temporarily bypass cache and see changes to your site in real-time.
<h3>Network</h3>
1) Enable <b>HTTP/3 (with QUIC)</b> - Accelerates HTTP requests by using QUIC, which provides encryption and performance improvements compared to TCP and TLS.<br>
2) Enable <b>0-RTT Connection Resumption</b> - Improves performance for clients who have previously connected to your website.
<h3>Apps (Optional)</h3>
Cloudflare provides a variety of <a href="https://www.cloudflare.com/apps/">apps</a> that you can easily install onto your site. These apps range from data-driven to User experience. One of my favorite apps is <a href="https://www.cloudflare.com/apps/adsenseguard">Adsense Guard</a>. Adsense Guards protects your adsense account from receiving invalid clicks on your ads. There are similar apps available that you can test out as well.
<h3>Scrape Shield</h3>
1) Disable <b>Email Address Obfuscation</b> (Optional). Enabling allows you to display obfuscated email addresses on your website to prevent harvesting by bots and spammers. I did not require this service so I turned it off to require one less resource.
2) Enable <b>Server-side Excludes</b> - Automatically hide specific content from disreputable visitors.
3) Enable <b>Hotlink Protection</b> - Protect your images from off-site linking.<hr>Thank you for reading. If you have any additional tips for optimizing your Cloudflare settings, please share.
<br>