2

I'm trying to figure out how the browsers handle the hashes in the url requests and the page rendering.

For example, let's say I go to www.example.com/#footer.

When I request this URL the browser makes the GET request to the www.example.com but doesn't have the #footer in the request.

When the page loads, the browser knows I asked for the #footer and jumps to that location.

What happens in the more complex situations when I do a redirect? For example, let's say I 301 redirect to www.example.com/birds/#middle. How does the browser know that it can jump to the #middle if hash is not part of the request URL?

Also how does web server know that I'm about to jump to particular anchor #hash so that it can serve content just for #hash? (Like facebook does when you go from one section to another. Only #hash anchor tag changes.)

bodacydo
  • 75,521
  • 93
  • 229
  • 319

1 Answers1

2

They called anchors here is definition and examples. Once the page loaded the browser is looking for this "anchor" and moves page there if it finds it.

Sergey Novikov
  • 644
  • 1
  • 4
  • 14
  • Thanks. I thought they were called #hashtags. I'll read your blog page that you linked to. – bodacydo Aug 07 '15 at 19:58
  • Thanks for edit. How does web server know that the browser will move to particular anchor though? Anchor hash tag is not part of request as far as I know? – bodacydo Aug 07 '15 at 19:59
  • Browser knows because it is part of a w3c standard and ancor is part of the link (or Get request for that matter). – Sergey Novikov Aug 07 '15 at 20:05
  • As far as I know Get request doesnt include anchor? Get request only include URL up to hash. Browser somehow maintains #hash state separately from server. Can you confirm or deny? – bodacydo Aug 07 '15 at 20:06
  • Well, it appears that anchors or as also refered Fragment identifiers (https://en.wikipedia.org/wiki/Fragment_identifier) according to this https://en.wikipedia.org/wiki/Uniform_resource_locator are part of URL. So they are part of the link and browser knows it when you clik. This question answers how server might know about fragemnt ids http://stackoverflow.com/questions/13503213/how-to-get-the-url-fragment-identifier-from-httpservletrequest the fact that they are not part of Get itself is interesting, didn't know befere stated to look. – Sergey Novikov Aug 07 '15 at 20:33