Joel Regus
Photo by Diana Polekhina on Unsplash

URL Length Limits

By Joel Regus on May 28, 2020 · 4 min read
Programming URL

What are the current limits on how long a valid URL can be?

Introduction

How long can a URL be before you throw an error?

TLDR

Although there are no official URL length limits, in practice it is best to keep them under 2048 bytes in order to maintain compatibility with old Internet Explorer browsers.

Browsers

Browser Maximum URL Size Address Bar document.location or Anchor Tag Notes
Internet Explorer 2048 B 2047 B 5120 B Microsoft Internet Explorer has a maximum uniform resource locator (URL) length of 2,083 characters. Internet Explorer also has a maximum path length of 2,048 characters. This limit applies to both POST request and GET request URLs. If you are using the GET method, you are limited to a maximum of 2,048 characters, minus the number of characters in the actual path.
Edge 81578 B 2047 B 10240 B  
Mozilla Firefox >100 KB >64KB >64 KB The address bar doesn’t shows any characters beyond 65,536 characters. But the URL Size can be more than that, though you cannot view it in the address bar. This holds for FireFox 1.5 up until the current FireFox version
Opera >200 KB     The URL is completely visible in the address bar even at such a big range.
Chrome >100 KB 32779 KB >64 KB Similar to Firefox, but the address bar can only show 32kb worth of characters.
Safari >100 KB >64 KB >64 KB Similar to FireFox.

Chrome

In general, the web platform does not have limits on the length of URLs (although 2^31 is a common limit). 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.

Ensure that the client behaves reasonably if the length of the URL exceeds any limits:

Safari

Safari recently added this feature:

Limit HTTP referer to 4kb Use the origin if it's longer, unless the origin is too long. This matches the behavior of other browsers.

Bug Tracker 1

Bug Tracker 2

Bug Tracker 3

CDNs

CDNs also impose limits on URI length, and some will return a 414 Too long request when these limits are reached, for example:

Name Limit
Akamai 8 KB
Fastly 8 KB
CloudFront 8 KB
CloudFlare 32 KB

Servers

Server Maximum URL Size Notes
Apache >128 KB The size is changed using the LimitRequestLine setting of the server
IIS >16 KB Default value is 16 KB and maximum limit is 16 MB
Lotus Notes 4 KB

NGINX

Syntax: large_client_header_buffers number size;
Default: large_client_header_buffers 4 8k;
Context: httpserver

Sets the maximum _number_ and _size_ of buffers used for reading large client request header. A request line cannot exceed the size of one buffer, or the 414 (Request-URI Too Large) error is returned to the client. A request header field cannot exceed the size of one buffer as well, or the 400 (Bad Request) error is returned to the client. Buffers are allocated only on demand. By default, the buffer size is equal to 8K bytes. If after the end of request processing a connection is transitioned into the keep-alive state, these buffers are released.

Source

document.referrer and HTTP referer header

If the result of serializing referrerURL is a string whose length is greater than 4096, set referrerURL to referrerOrigin If length of the referrer is greater than 4096 then the URL will be truncated to just the origin.

Spec

DFP DoubleClick Limits

Type Limit
Google Publisher Tags (GPT) 8,192 characters
Simple URL tags 4,096 characters

Source

How many bits or bytes are there in a character?

function getTotalBytesInString(string) {
    if (typeof string !== "string") {
        return false;
    }

    if (window.Blob) {
        return new Blob([string]).size;
    }

    return encodeURI(string).split(/%..|./).length - 1;
}

Source

Example of bits

Test Script

Here is a quick and dirty script to test out URL limits, you will need to change the baseUrl to a URL to resource on your own server.

var targetLength = 8914;
var baseUrl = "INSERT_URL_TO_YOUR_RESOURCE_HERE" + "?a=";
var str = (new Array(targetLength - baseUrl.length)).fill("a").join("");
var url = baseUrl + str;

console.log("Length: " + url.length);

var img = new Image();
img.src = url;

Sources

Techno Manor

Chromium

Stack Overflow 1

Stack Overflow 2

Want to contact me?

Feel free to email me if you would like to get in touch.