Maximum length of URL fragments (hash)

11,435

Solution 1

There is definitely a length for the whole url.

Read

RFC2616 - Hypertext Transfer Protocol

Maximum URL length is 2,083 characters in Internet Explorer

Solution 2

The hash is client side only, so the rules for HTTP may not apply to it.

Solution 3

It depends on the browser. I found that in safari, chrome, and Firefox, an URL with a long hash is legal, but if it is a param send to the server, the browser will display an 414 or 413 error.

for example: an URL like http://www.stackoverflow.com/?abc#{hash value with 100 thousand characters} will be ok. and you can use location.hash to get the hash value in javascript but an URL like http://www.stackoverflow.com/?abc&{query with 100 thousand characters} will be illegal, if you paste this link in the address bar, a 413 error code will be given and the message is the client issued a request that was too long. If that is a link in a web page, in my computer, Nginx response the 414 error message.

I don't know the situation in IE.

So I think, the limitation of the length of URL is just for transmission or HTTP server, the browser will check it sometimes, but not every time, and it will always be allowed to be used as a hash.

Share:
11,435
Andreas Köberle
Author by

Andreas Köberle

Updated on June 12, 2022

Comments

  • Andreas Köberle
    Andreas Köberle about 2 years

    Is there a length limit for the fragment part of an URL (also known as the hash)?

  • Rick
    Rick over 7 years
    RFC2616 doesn't mention fragments except to say: "The URI MUST NOT include a fragment"
  • Sai Dubbaka
    Sai Dubbaka over 6 years
    The "hash" is actually the URL Fragment and is not sent to the server, hence the length limitation from a server perspective doesn't apply.
  • Lukas Lentner
    Lukas Lentner almost 4 years
    This did not answer the question
  • Moshe Jonathan Gordon Radian
    Moshe Jonathan Gordon Radian over 3 years
    Did you find any official (docs) information regarding the client side limitations (or lack thereof)?