Skip to content

Instantly share code, notes, and snippets.

@franky47
Created February 11, 2025 11:06
Show Gist options
  • Save franky47/5a8e9aab42536224bb93f840b8f7f57f to your computer and use it in GitHub Desktop.
Save franky47/5a8e9aab42536224bb93f840b8f7f57f to your computer and use it in GitHub Desktop.
Vanilla HTML URL state
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Vanilla</title>
</head>
<body>
<label style="display: flex; gap: 0.5rem; align-items: center">
<input type="range" id="slider" />
<span id="value"></span>
</label>
<script type="module">
addEventListener('load', () => {
const slider = document.getElementById('slider')
const label = document.getElementById('value')
const searchParams = new URLSearchParams(location.search)
slider.setAttribute('value', searchParams.get('value') || '50')
label.textContent = slider.value
slider.addEventListener('input', event => {
label.textContent = event.target.value
history.replaceState(null, '', `?value=${event.target.value}`)
})
})
</script>
</body>
</html>
@franky47
Copy link
Author

Showcases how updating the URL (using the History API) at direct event rates can cause failures due to rate-limiting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment