Menu

Post image 1
Post image 2
1 / 2
0

URL Encoding: The Developer's Swiss Army Knife You're Probably Using Wrong

DEV Community·zhihu wu·23 days ago
#nCesjntd
Reading 0:00
15s threshold

URL Encoding: The Developer's Swiss Army Knife You're Probably Using Wrong If you've built anything that touches the web, you've dealt with URL encoding. And if you're honest, you've probably Googled "encodeURI vs encodeURIComponent" at least five times this year. I know I have. Here's the mental model that finally made it stick for me: The TL;DR encodeURI() = "I'm encoding a complete URL" → keeps structural chars like / ? & # encodeURIComponent() = "I'm encoding ONE piece of data" → encodes EVERYTHING except A-Z a-z 0-9 - _ . ! ~ * ' ( ) When Things Go Wrong Last week I spent an hour debugging a 500 error from a payment gateway. The culprit? I used encodeURI() on a query parameter that contained a # character. The browser interpreted everything after # as a fragment identifier and never sent it to the server. encodeURIComponent() would have caught it. The 3 Rules I Now Live By Query string values → ALWAYS encodeURIComponent() . No exceptions.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More