Home
/
WordPress Tutorials
/
SG Optimizer Plugin Tutorial
/
Cloudflare Full Page Caching in SG Optimizer

Cloudflare Full Page Caching in SG Optimizer

This option will enable full-page caching on your Cloudflare CDN server edges. This will reduce the load on your SiteGround server and improve the loading speed of your pages because by default Cloudflare will cache only your static resources.

Activating the Optimization

If you have set your Cloudflare properly, a Cloudflare optimization tab will be displayed in your SG Optimizer plugin. To view it, log into your WordPress admin dashboard > SG Optimizer > Cloudflare tab, located right next to the Speed Test tab.

If the tab is not present, please make sure that you have properly configured your Cloudflare and your application is working properly through ‘www’. Log out and log in again and the tab should become visible.

After you enable the Cloudflare Full Page Caching optimization from the toggle button, you will have to fill in the necessary information in order to complete the settings.

The email should be the one you are using for your Cloudflare Account. The API Key can be found in the link above the text field. You will be automatically redirected to your API key page where you need to click on the View button next to Global API Key (if it’s necessary, log into your Cloudflare account, click on your site, scroll down and click on Get your API Token > API Tokens > Global API Key > View).

After successful authentication, all Page rules from your Cloudflare account for that website will be removed in order to ensure the proper work of our optimization. Keep in mind that the rules will not be restored if you deauthenticate and deactivate the optimization from our plugin. Also, an ‘sg_worker’ script will be added to your Cloudflare account in order to bypass the cache for logged in users.

The CDN’s workers have a limit of 100,000 requests/day and 1000 requests/min. If you are hitting those limits, you will have to upgrade your CDN account in order to fit your needs.

After the configuration is complete, you should see these response headers present in your browser. You can check them by right-clicking on your page > Inspect > Network and then click on the www.yourwebsite.domain. Then, look for the Headers tab in your browser. If everything is set correctly, you should be able to see the following headers:

cf-cache-status: HIT
server: cloudflare
sg-optimizer-cache-control: s-max-age=604800, s-maxage=604800, max-age=60
sg-optimizer-worker-status: hit

This means that the content of your website has been served from the CDN, cached, and the worker was set up properly. For logged-in users, the following headers should be visible:

cf-cache-status: DYNAMIC
server: cloudflare
sg-optimizer-cache-control: no-store, no-cache, max-age=0
sg-optimizer-worker-status: bypass

This means that the content is being served from the origin server, it is the latest one and will instruct the CDN not to cache that content. This will ensure that content visible for logged in users will not be cached. The ‘x-proxy-cache’ header should have the status ‘BYPASS’ since the content served to your users is non-cached.

If you get other ‘cache-header’ status or the ‘sg-optimizer-cache-control’ and ‘sg-optimizer-worker-status’ is missing, there is a high probability that your website was not properly configured to work through the CDN, or another plugin or setting is preventing our headers from being sent.

Purging the Cloudflare Cache

When configured correctly, you will be able to purge the Cloudflare cache through the Optimization tab.

Please, keep in mind it may take some time to purge the cache on all edges of the CDN. This is also stated in their documentation and it is not something that our plugin can speed up.

Deactivating the Optimization

If you wish to deactivate the optimization, simply click on Deauthenticate. This will remove the settings from your CDN account and will remove the worker we have previously set up. After that, you can disable the optimization from the button.

If you wish to check if the deauthentication was successful, you can go to your account and click on Workers. The list should be empty. If for some reason the ‘sg_worker’ is still present, you can safely remove it from your account.

Share This Article