tl;dr: an empty string for your link, e.g.
The other day I was trying to write some HTML to give the user the ability to reload the document in its exact state by clicking on a link (same functionality as if they hit
R on their keyboard, or clicked “reload” in the browser UI).
My first attempt was to use a relative reference to the document, e.g.
But then I thought, “I don’t know if this will preserve the existing query parameters in the URL…” Turns out, it doesn’t.
“What about a
<form>?” I thought.
Nope. Doesn’t work either.
So I started searching:
“how do you reload an html document using the
<a> tag and preserve query parameters?”
But I could not find an answer.
But I digress.
At that point, it seemed pretty inconceivable to me that there was really no way to reload a document using only HTML that preserved the state of the URL.
So I turned to Mastodon and Twitter for help.
Fortunately, Ryan Florence (who knows a lot about routing on the web) had the answer: use an
href with an empty string.
Sure enough, that worked. If you hover a link like that in the browser, you’ll see the little link preview show the exact same URL as your current document.