Experiences are better when they are local. Knowing the approximate location of an end user allows for localization of content and regulation of access based on regional distribution rights.

Country switcher

Fastly features

Our geolocation feature, given an IP address, will provide information such as latitude, longitude, continent, country, city, and region, and is exposed in VCL services and all Compute languages. Learn more about how to use our geolocation features. Here's an example of a geolocation dataset for an IP address belonging to an AWS server in Tokyo, Japan:

"as_name": " inc.",
"as_number": 16509,
"area_code": 0,
"city": "tokyo",
"conn_speed": "broadband",
"conn_type": "wired",
"continent": "AS",
"country_code": "JP",
"country_code3": "JPN",
"country_name": "japan",
"latitude": 35.68,
"longitude": 139.75,
"metro_code": 392001,
"postal_code": "100-0001",
"proxy_description": "cloud",
"proxy_type": "hosting",
"region": "13",
"utc_offset": 900

Ideas and typical uses

Geolocation data can be used for a wide variety of purposes:

  • Display data-collection or cookie consent content that is relevant to the end-user's country.
  • Redirect to a local domain or edition of your website, or offer an option to the user to do so.
  • Provide localized stock levels or delivery options.
  • Block traffic from regions where you are not licensed to deliver content.
  • Block regions that are originating DDoS attacks, or subject requests from those regions to additional checks, such as a CAPTCHA.
  • Trigger additional security measures if a user accesses your site from a different country to the one they are normally in.
  • Report geolocation data as part of your request logging to better understand your customers.
  • Make an API endpoint for your front end code to use to get access to geolocation data in the browser or your client-side app.

Cache variation

Many common use cases for geolocation involve sending geo data to an origin server in an HTTP header (see example), and using that information to customize the response. In these cases, ensure that the response has an appropriate Vary header, or make it not cacheable.


The following demos, tutorials, starter kits, and code examples are relevant to this use case. Try them out!


Sites running on Fastly you can browse. See the principles working for an end user.

Weather AppUse Fastly's geolocation and a third-party weather API to build a synthetic HTML response using a template.


Step by step instructions. Build and learn.

GeofencingYour site is available only in certain regions, or offers content that varies between regions. Whether it's at the country level or down to the square kilometer, Fastly's geolocation data offers a way to group and route traffic in a regionally specific way.
Request enrichmentYou need to fetch data from external APIs and add extra headers with additional useful information to the origin

Code examples

Snippets of code ready to copy and paste.

Add time zone offset to requestsDivide the world into time bands of custom size and forward time zone data to your origin server.
Cache 'near you' content for each area using lat/long gridBucket users into small grid squares to allow for hyper-local content caching (e.g., "stores near you", "local offers").
Geo-IP API at the edgeCreate an API endpoint for fetching geolocation data for the requesting browser, implemented 100% at the edge. The response should show your current approximate location, but no requests to any origin servers.
Geofence / block access to content by regionGroup countries to cache content by custom regions or reject requests from some regions entirely.
Tag requests with geolocation dataAdd geolocation data about the client browser as extra headers in any requests from Fastly to your origin.
Throttling per country over configurable time periodsAdjust the maximum TCP socket pacing for connections at peak times of day in busy regions.

Real world usage

Geolocation is one of the most popular uses of Fastly and a very large number of our customers make use of geo data as part of their services. Here are some featured use cases:

Financial Times

World-leading business news provider the Financial Times forwards requests to different origin servers depending on where in the world the request originates. Because they have origin servers in multiple locations, using country and continent geolocation data, they can choose to route requests from the edge to an origin server closer to the user.

The Weather Channel

The Weather Channel redirects homepage requests to a URL that provides a forecast for the user's location, down to the city level.

The Guardian

The Guardian uses the location of the user to determine whether to show the US, UK or Australian edition of the website.


1stdibs is the world’s leading online marketplace for rare and desirable objects. They use geolocation data as part of their DDoS mitigation. With geography detection, they can quickly identify and block malicious IP addresses during DDoS attacks.

Fastly’s technology allows us to handle attacks better than anything else while still giving us control.

Best practices

Here are some of the most important things to bear in mind when you use geolocation in your Fastly services:

  • Continents are not standardized: Continent designations are not widely used standards and are best avoided. Notably, the continent of Europe is not the same as the political entity of the European Union.
  • Don't use geolocation for language: Remember, the ability to speak a language is a property of a person, not the place where they are currently located. If possible, use the Accept-Language header to customize language preferences.

Blogs and articles