Subscribe to receive notifications of new posts:

Location-based personalization at the edge with Cloudflare Workers


2 min read
Location-based personalization at the edge with Cloudflare Workers

We’re excited to announce an update to Cloudflare Workers, our serverless code platform built on our global network. Geolocation data is now accessible and free for all developers on our Workers platform, including users on the free plan!

You can now serve personalized experiences for users based on their location using Workers. Personalization is critical to building intuitive apps for users and it unlocks new possibilities for what you can build on our platform. Whether you’re building a social networking app or an automatic shipping cost estimator for an e-commerce site, a one-size-fits-all experience doesn’t cut it. Location-based personalization helps you show what’s most relevant to your users, be it tickets for movies in their area or content in their local language.

With geolocation data available on the server side, there’s no configuration needed for users to set their location.

Each request to a Worker includes the user’s (example data shown):

  • Country: “US”
  • City: “Austin”
  • Continent: “NA”
  • Latitude: "30.27130"
  • Longitude: “-97.74260”
  • Postal code: "78701"
  • Metro code(dma): “635”
  • Region: “Texas”
  • Timezone: “America/Chicago”

Geolocation data on Workers makes it even easier to build server rendered apps and customized services.

Refer to the documentation to learn more.

In case you need some inspiration on how you can use this data, here are some quick and fun examples to get you started:

Hello World

Hello World! This is a simple Worker to show you the available geolocation data fields and how to access them. Refer to the source code and live demo to learn more.

Personalized UI Design

This is a Worker that customizes the user interface based on the user’s local time. The background changes throughout the day showing blue gradients during daylight and darker gradients at night. It’d be interesting to implement automatic dark mode for apps on Workers using a similar approach as well.

Traditionally, websites customize the user experience by loading JavaScript and cookies into the client side, which causes longer load times and other challenges. Web apps like the example above would have to store cookies and have delays updating the visuals to wait for the client side code to personalize the experience for the user. With Workers, you can take full advantage of server rendered apps and eliminate these challenges while decreasing load times.

Refer to the source code and live demo to learn more.

Location Based Applications

This is a Worker reporting the air quality near your location using the World Air Quality Project’s API. For other ideas, you could build a simple analytics service or a review platform for local businesses.

Refer to the source code and live demo to learn more.

These are just some examples of what you can make using geolocation. We are excited to see what you build and we’d love to hear from you in our Workers Discord.

We protect entire corporate networks, help customers build Internet-scale applications efficiently, accelerate any website or Internet application, ward off DDoS attacks, keep hackers at bay, and can help you on your journey to Zero Trust.

Visit from any device to get started with our free app that makes your Internet faster and safer.

To learn more about our mission to help build a better Internet, start here. If you're looking for a new career direction, check out our open positions.
Developer WeekDevelopersCloudflare WorkersProduct NewsServerless

Follow on X

David Song|@davidtsong