Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum length of URL fragments (hash)

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

like image 557
Andreas Köberle Avatar asked Oct 15 '09 11:10

Andreas Köberle


People also ask

How long can a URL hash be?

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.

How long is too long for a URL?

Browsers' URL length limits The maximum length of a URL in the address bar is 2048 characters. However, the successful processing of extra-long links by the browser doesn't mean that a search robot will be able to process them too.

What is the maximum length of a URL in Chrome?

Chrome limits URLs to a maximum length of 2MB for practical reasons and to avoid causing denial-of-service problems in inter-process communication. On most platforms, Chrome's omnibox limits URL display to 32kB ( kMaxURLDisplayChars ) although a 1kB limit is used on VR platforms.

What are URL fragments?

A fragment is an internal page reference, sometimes called a named anchor. It usually appears at the end of a URL and begins with a hash (#) character followed by an identifier. It refers to a section within a web page. In HTML documents, the browser looks for an anchor tag with a name attribute matching the fragment.


2 Answers

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

like image 104
Ben Noland Avatar answered Sep 21 '22 13:09

Ben Noland


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.

like image 31
LCB Avatar answered Sep 25 '22 13:09

LCB