Reputation: 65
I understand there's no theoretical character limit to a URL, but it's 255 for the domain.
The consensus seems to indicate a safe bet is about 2000 characters, but it all depends on the browser and web server.
The twitter API faq for t.co doesn't mention a limit for expanded links, but instead only the shortened links.
I want to use javascript to store self-contained data in the URL, such as with parameters, for object properties that reference the data.
The data stored can be large, so I also want to compress the data so that it will fit in a URL string. This will also require encoding the compressed binary data into Base64 characters that are valid in a URL.
function compressAndEncode(content) {
const compressed = compress(content);
const encoded = btoa(String.fromCharCode.apply(null, new Uint8Array(compressed)));
const params = encodeURIComponent(encoded);
const url = new URL(window.location.href);
url.searchParams.set('file', params);
history.pushState(null, '', url);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = `data:application/octet-stream;base64,${encoded}`;
downloadLink.download = 'compressed_file';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Compressed File';
}
The code works fine, but there are limits, such as browser limits, and more specifically, twitter link limits for sharing on the platform, which uses it's own in-house link shortener, t.co
.
Does anyone know what the maximum character count for a fully-expanded t.co
link is, regardless of browser or target web server?
Is there a quick and easy way to check?
What happens if a link is too long?
Upvotes: -1
Views: 210
Reputation: 21
I've discovered after testing the boundaries of this using a URL with a dynamically generated query string in it that the t.co service seems to fail at exactly 4090 characters.
At 4089 characters my URL will consistently generate a valid card and allow posting, and at 4090 characters the tweet composer stops recognizing my URL, does not shorten it, and will not permit the tweet
Upvotes: 1