encodeURI vs encodeURIComponent
JavaScript provides two built-in functions:
- encodeURI ??preserves characters that have a structural role in URLs:
: / ? # [ ] @ ! $ & ' ( ) * + , ; =. Use to encode an entire URL. - encodeURIComponent ??escapes everything except
A-Z a-z 0-9 - _ . ! ~ * ' ( ). Use for individual query parameter values, path segments, etc.
Common Characters
- Space ??
%20(or+in query strings, application/x-www-form-urlencoded) /??%2F(in component encoding only)???%3F&??%26=??%3Dcaf챕??caf%C3%A9(UTF-8 then percent-encoded)