0

I would like to determine the response header of people who use my website. It is a private website I made for friends but depending on from where you connect I'd like to enable/disable features. A friend of mine chipped in and wrote a snippet which gets the job done, however it is not efficient imo. Moreover, it creates a request which reloads the whole site in the background (which takes quite long).

Here's his code:

        var request = new XMLHttpRequest();
        request.open("GET", document.location, false);
        request.send(null);
        var x = request.getResponseHeader("x-custom-one");
        var x = request.getResponseHeader("y-custom-second");

Do I understand it right that through settings the second argument for the open method to "document.location" it sends the request to the location where the file is located from which the method is called? That leads to a pretty massive request which loads the whole site in the background.

Anyone got any input for me? Thanks a ton.

  • I don't understand what you are trying to do at all. Do you want code on the server or on the client? It sounds like you want to check *request* headers to find out who is connecting to your website. But the code you have seems to run in the browser. What exactly are those custom headers and who sets them? – Thilo Oct 17 '16 at 09:30
  • You are setting `async = false` here, so this is not loading anything *in the background*. – Thilo Oct 17 '16 at 09:30
  • Check this, http://stackoverflow.com/questions/220231/accessing-the-web-pages-http-headers-in-javascript/220233#220233 – Ibrahim Oct 17 '16 at 09:42
  • @Ibrahim "request.open('HEAD', document.location, true);" reloads the whole page which costs a lot of time :s –  Oct 17 '16 at 10:35

0 Answers0