Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

249
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda