Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
How to use request location header to modify static site via Javascript?

Objective: I'm trying to add a pop-up on my pages tailored to the visitors country.

Tech: I have a static site hosted on Github Pages, with Cloudflare as CDN.

I'm using this Cloudflare managed worker to add the visitors country to their request.

How do I access this "cf-ipcountry" value from the request header in Javascript and do something with it?

--

Edit: If it's not possible to get it directly, could I use a Cloudflare worker to parse the request and modify the page load? Something like this (but instead of listening for an auth token I listen for the country code in the request header?)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Request headers are not exposed to client-side JavaScript.

Even if they were, the request from the browser to Cloudflare is a different request to the one from Cloudflare to Github Pages and the header you want is on the request that the browser doesn't have access to.

So: You can't.


You need server-side programming capabilities for this.

If you want to use the header added by Cloudflare then you need it on the server you are hosting the site on.

Otherwise, your minimum is a third-party GeoIP web-service that supports CORS (or the old, risky JSONP) that you can hit with Ajax.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!