Subscribe to receive notifications of new posts:

Location-based personalization at the edge with Cloudflare Workers

2021-04-13

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.

Cloudflare's connectivity cloud protects entire corporate networks, helps customers build Internet-scale applications efficiently, accelerates any website or Internet application, wards off DDoS attacks, keeps hackers at bay, and can help you on your journey to Zero Trust.

Visit 1.1.1.1 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
Cloudflare|@cloudflare

Related posts

October 09, 2024 1:00 PM

Improving platform resilience at Cloudflare through automation

We realized that we need a way to automatically heal our platform from an operations perspective, and designed and built a workflow orchestration platform to provide these self-healing capabilities across our global network. We explore how this has helped us to reduce the impact on our customers due to operational issues, and the rich variety of similar problems it has empowered us to solve....

October 08, 2024 1:00 PM

Cloudflare acquires Kivera to add simple, preventive cloud security to Cloudflare One

The acquisition and integration of Kivera broadens the scope of Cloudflare’s SASE platform beyond just apps, incorporating increased cloud security through proactive configuration management of cloud services. ...

September 27, 2024 1:00 PM

Our container platform is in production. It has GPUs. Here’s an early look

We’ve been working on something new — a platform for running containers across Cloudflare’s network. We already use it in production, for AI inference and more. Today we want to share an early look at how it’s built, why we built it, and how we use it ourselves. ...