What is URL encoding?
URL encoding replaces unsafe or reserved characters with percent-encoded sequences so they can safely appear in URLs.
Should I encode an entire URL?
Usually you encode individual parts such as query parameter values. Encode a full URL only when it is being passed as a value inside another URL.
Why does a space become %20?
A raw space is not safe in URLs, so percent-encoding represents it as %20.
Why does a plus sign sometimes become a space?
In form-style query encoding, plus signs can represent spaces. If you need a literal plus sign, such as in C++ or a phone number, encode it as %2B.
Is my URL sent anywhere?
No. Encoding and decoding run locally in your browser after the page loads, so pasted URLs and query strings are not uploaded for processing.
When should I use encodeURIComponent?
Use encodeURIComponent for individual query parameter values, such as a search term, redirect URL, or campaign value. Encoding a full URL as one string is usually only needed when nesting it inside another URL.
How should I encode a redirect URL parameter?
Encode the entire redirect URL before placing it inside another URL parameter. This keeps its question marks, ampersands, slashes, and hash signs from being interpreted as part of the outer URL.