In simple words, a serverless worker lets you run small bits of JavaScript functionality important for getting stuff done on the internet without the need of your own cloud server. For the offical pitch have a read of Cloudflare Workers.

Digital marketing use cases for Cloudflare serverless workers include:

  1. Custom URL and specific country redirects.
  2. Middleware between services.
  3. API request caching.
  4. Logging.

To learn more about use cases have a read of Cloudflare serverless worker examples.

In practice to setup a Cloudflare serverless worker you will need the following:

  1. Cloudflare account with serverless workers enabled.
  2. A serverless worker script loaded.
  3. If required a subdomain or path on your DNS for the serverless worker endpoint. Note if using a subdomain then you will need to setup a corresponding "A" record pointing to a dummy IP (e.g. 192.0.2.1).

In the case of using a script like the example for bulk redirects ensure that the path that you map your worker to has the required wildcards. Also note that with this script you may not need to change the path with a split.

Another question that you might ask is, why can't I just put a bit of JavaScript publicly on the internet to get the job done? One of the main differences between hosting JavaScript publicly and on Cloudflare as a serverless worker is that with a Cloudflare serverless worker private environment variables can be hidden.

A typical Cloudflare serverless worker process flow with hidden environment variables:

  1. Access data and/or content via an APIs where secure environment variables are required.
  2. Apply some caching on Cloudflare so that you don't have to hit the API origin server and potentially get rate limited.
  3. Apply some functions to the data.
  4. Trigger some other API to do something important and exciting, again potentially where secure environment variables are required.
  5. Then, expose the result via an API all to be consumed in a website via JQuery.

Finally, what is really exciting about Cloudflare serverless workers is that they are relatively inexpensive when compared to dedicated API hosting and much easier to setup than an AWS Lambda function.


Help make an awesome list

Share a comment about a Cloudflare serverless worker digital marketing use case.

Let's continue the conversation.

SUBSCRIBE