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 integrating with Cloudflare. After success deploying, if you set Cloudflare cache to make your website faster I guess you will face issue relate with a cache.

First, if you push or make changes, your website not instantly follow the changes. From my experience that because of cache! So to handle this case we need to purge every time we make a change and Git have a handy feature to make it automatically, they 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 in 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, that have separated config file, to make the script work, we also need to create a configuration file in the user directory.

cd ~

And add detail about Cloudflare configuration

[email protected]

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