In the last post about deploying Now with Cloudflare, I have been describing in general how to deploy a project using Now and how to integrate with Cloudflare. After success deploying, if you set Cloudflare cache to make your website faster I guess you will face issues related to a cache.

First, if you push or make changes, your website does not instantly follow the changes. From my experience that is because of cache! So to handle this case we need to purge every time we make a change and Git has a handy feature to make it automatically, which call hooks.

Git hooks are scripts that Git executes before or after events such as: commit, push, and receive. Git hooks are a built-in feature - no need to download anything. Git hooks are run locally.[1]

To use this feature you only need to create a shell script and make it executable then put it in the hooks directory in .git on a project root. So that will be like this:

cd my_project/.git/hooks
touch pre-commit
chmod +x pre-commit

Inside file pre-commit, we can add shell script to call Cloudflare API like this:

As you can see, we have separated the config file, to make the script work, we also need to create a configuration file in the user directory.

cd ~

And add detail about the Cloudflare configuration

CF_EMAIL=your.[email protected]

To generate an API key in Cloudflare, please refer to this link. After all is complete, now you can deploy and also tell Cloudflare to purge your cache, so your web visitor always gets the latest data.