JavaScript

Collections

Discover the Magic of Portals: A Beginner’s Guide to React’s Most Powerful Tool

Portals allow you to render components outside of their parent component’s tree.

When should you use portals?

  • Modals and dialogs
  • Tooltips and popovers
  • Overlaying content

15 Useful JavaScript Tips

Event listeners run only once

element.addEventListener("click", () => console.log("I run only once"), {
  once: true,
})

element’s dataset

<div id="user" data-name="Maxwell" data-age="32" data-something="Some Data">
  Hello Maxwell
</div>
<script>
  const user = document.getElementById("user")

  console.log(user.dataset)
  // { name: "Maxwell", age: "32", something: "Some Data" }

  console.log(user.dataset.name) // "Maxwell"
  console.log(user.dataset.age) // "32"
  console.log(user.dataset.something) // "Some Data"
</script>

API

Reliably Send an HTTP Request as a User Leaves a Page

Browsers do not guarantee that HTTP requests will complete if a page is unloaded, such as when a user navigates to a new page. This can cause issues for requests meant to log analytics data. Two reliable methods are available: using the "keepalive" flag with fetch requests, or the sendBeacon() API, which sends low priority requests. Both ensure requests are not cancelled even after page navigation. The article also discusses delaying navigation until requests finish, but this hurts the user experience. It provides examples demonstrating unreliable requests and how the different methods work. In summary, sendBeacon() is best for simple logs as it has cleaner code, while fetch with keepalive allows for custom headers and GET requests. The author hopes sharing these lessons learned will help others avoid similar analytics logging issues.


Children
  1. Angular, Qwik Creator on How JS Frameworks Handle Reactivity
  2. Closing Modals By Pressing the Back Button in Vue.js
  3. Demystifying Fresh — Build Your own Islands of Interactivity
  4. Detecting Rendered Line Breaks in a Text Node in JavaScript
  5. Divops - javascript build system, CI, ...
  6. Draggable objects
  7. Event Delegation with Lokalised Anchor
  8. Interesting
  9. JavaScript Closure: A Simple Explanation
  10. Javascript Performance
  11. Javascript Tools
  12. Javascript debug
  13. Language
  14. Lit
  15. Low Javascript
  16. Next.js
  17. Node
  18. React
  19. Reasons to avoid Javascript CDNs
  20. Reliably Send an HTTP Request as a User Leaves a Page
  21. Say goodbye to resource-caching across sites and domains
  22. Snippets
  23. Statistics about javascript
  24. The balance has shifted away from SPAs
  25. Trouble Shooting
  26. Using Web Components With Next (or Any SSR Framework)
  27. Virtual DOM is pure overhead
  28. Vue
  29. We Don't Need Faster Frameworks, We Need Better Tooling
  30. WebSockets vs Server-Sent-Events vs Long-Polling vs WebRTC vs WebTransport