Dark Mode End to End: OS Preference, Toggle, and No Flash of White
Respect the system setting, let users override it, remember the choice, and never flash the wrong theme on load - the complete wiring across CSS, JS and PHP.
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.
Respect the system setting, let users override it, remember the choice, and never flash the wrong theme on load - the complete wiring across CSS, JS and PHP.
The gray-box loading experience becomes a soft preview of the real image - generated at upload with GD, inlined as a data URI, crossfaded away on load.
Search-as-you-type touches four failure modes at once - request spam, stale responses, LIKE wildcards and unbounded scans. The complete pattern, both sides of the wire.
Unlimited password guesses is a breach schedule; hard lockouts are a denial-of-service gift. The middle path: counting failures per account AND per IP, with exponential delays.
A hidden token, a session comparison, a header for AJAX - the whole defense is 30 lines of PHP and JS. Build it once by hand and framework CSRF errors stop being mysterious.
You don't migrate a decade of jQuery in one heroic rewrite - you make the two worlds interoperate. Element extraction, wrapping, iteration and event bridging, mapped precisely.
jQuery keeps a stack of every traversal you make. .end() pops it, .addBack() merges it - and suddenly one chain does what used to take three variables.
Chainability, per-element state, options with defaults, re-init safety - the four requirements of a proper $.fn plugin, in one compact pattern you can reuse forever.
Callback pyramids after fadeOut, logic that runs mid-animation, the queue backlog from impatient clicking - all solved by three methods most jQuery users never met.
.off("click") nukes every click handler including ones you don't own. Namespaces let you unbind exactly your handlers - one suffix, surgical cleanup.
PHP recompiles every file on every request unless OPcache says otherwise - and the default settings leave real performance on the table. Five ini lines, measurable wins.
Streaming big files through readfile ties up a PHP worker per download. The offload headers let PHP do the auth check, then hand the actual bytes back to the web server.