"3 Days Ago" Without a Library: Intl.RelativeTimeFormat
You do not need moment.js or dayjs to print "yesterday" or "in 3 weeks". The Intl API does relative time, in the user's own language, with zero dependencies.
Software Engineer
I build web applications and share what I learn along the way.
Step-by-step programming tutorials on PHP, JavaScript, Laravel, WordPress and more.
You do not need moment.js or dayjs to print "yesterday" or "in 3 weeks". The Intl API does relative time, in the user's own language, with zero dependencies.
Type document.designMode = "on" in the console and the entire page becomes editable like a document. Absurdly useful for copy reviews, screenshots and layout testing.
Ctrl+V with an image on the clipboard fires a paste event carrying a real File object. Ten lines of code turn any form into a screenshot-friendly uploader.
Checking window.innerWidth on every resize event is wasteful and drifts out of sync with your CSS. matchMedia gives JavaScript the same breakpoints CSS uses, with change events.
fetch() calls fired when a user closes the tab often never leave the browser. navigator.sendBeacon() exists precisely for this moment, and it is a one-line change.
Analytics batching, prefetching, cache warming - none of it should compete with user interaction. requestIdleCallback runs your low-priority work in the gaps.
Grouping an array of objects used to mean writing the same reduce() dance in every project. JavaScript finally does it natively, and the syntax is one line.
new FormData(form) reads every field in one call, posts natively with fetch, and Object.fromEntries turns it into JSON. You may never write form.elements loops again.
Users almost never report the JavaScript errors they hit. A global error handler, sendBeacon and a tiny PHP endpoint give you a self-hosted crash log for free.
Math.random-based IDs collide more than you think and are predictable by design. The browser ships a real UUID generator and a cryptographic random source - both one-liners.
Generators pause between values, which makes infinite sequences, cheap ID factories and stop-early pipelines natural - no arrays, no wasted work.
fetch() still cannot report upload progress reliably - but XMLHttpRequest has done it for fifteen years. The full pattern: progress events, a PHP receiver, and the config limits that silently break big uploads.