tips
67 tips Web-Development
One command, setting or habit at a time about Web-Development: what it does, the line to copy and a caveat or two.
Web development 52
-
Prints an error to the console only when the checked condition fails.
console.assert(items.length > 0, 'cart is empty', items) -
Turns the entire page into an editable document so you can type over any text.
document.designMode = "on" -
Logs a stack trace so you can see which code path called a function.
function save(item) { -
One button submits without validation while the main button still checks everything.
Save draft -
Fields for usernames, commands or codes stop getting red lines and corrected words.
spellcheck="false" -
Disable a whole group of inputs while a form is being sent, with one attribute.
const form = document.querySelector("#settings"); -
See the request that caused a redirect instead of an empty list after navigation.
Network panel > tick "Preserve log" in the toolbar -
Link to the exact sentence you mean, even on a page without anchors.
https://example.com/docs/setup#:~:text=back%20up%20the%20database -
A form result updates in place and is read out without moving focus.
Total: € <output name="total" for="qty">9.00</output> -
Sign-up and password change forms get generated passwords instead of an autofilled old one.
-
An upload button on a phone goes straight to the camera instead of the file picker.
accept="image/*" capture="environment"> -
A built-in gauge that changes color based on ranges you define.
low="0.7" high="0.9" optimum="0.2">92%</meter> -
Turn any request a page made into code you can tweak and run again.
Network panel > right-click the request > Copy > Copy as fetch -
A save button in a sticky footer can still submit a form elsewhere in the page.
-
Find the stylesheets and scripts that mostly ship dead weight to a page.
choose "Per function" or "Per block" > click the reload button in the panel -
Set a breakpoint on a function without finding it in the Sources panel.
// DevTools pauses on the first line of the function -
Phones download a small file and large screens a sharp one, from one img tag.
srcset="photo-400.jpg 400w, -
A modal closes on a backdrop click or Escape without a custom click handler.
-
Buttons can open modals and toggle popovers declaratively, with no JavaScript.
-
Pick defer for scripts that depend on each other and async for independent ones.
-
Builds a plain object from an array or Map of key-value pairs, handy after filtering entries.
const safe = Object.fromEntries( -
Resolves with the first promise that succeeds and only fails when all of them fail.
const data = await Promise.any([ -
Returns a copy of an array with one index replaced, so the original stays unchanged.
const arr = [1, 2, 3, 4, 5]; -
Removes several event listeners at once by aborting a shared AbortController signal.
const controller = new AbortController(); -
Checks whether an object has its own key, even for objects without a prototype.
const foo = Object.create(null); -
Assigns a default value only when the variable is null or undefined, keeping 0 and empty strings.
options.duration ??= 100; -
Replaces every occurrence of a string in one call, with no regex escaping.
"192.168.1.10".replaceAll(".", "-"); -
Runs tests with the test runner built into Node, no extra package needed.
test("async tests work too", async () => { -
Shows the chain of dependencies that caused a package to be installed.
npm explain glob -
Prints how long code took between two labelled console calls.
console.time("fetchData"); -
Maps an array and drops or adds items in one pass by returning arrays.
const a = [5, 4, -3, 20, 17, -33, -4, 18]; -
Formats dates and times in Dutch or any locale with the built-in Intl object.
// for example "28 november 2026 om 14:05" -
Returns every regex match including capture groups, readable with named groups.
const re = /(?<year>\d{4})-(?<month>\d{2})/g; -
Waits for an async iterable or list of promises and returns a normal array.
async function* pages() { -
Sets the label of the Enter key on mobile keyboards, like search, next or send.
-
Offers suggestions under a text input while still allowing any typed value.
-
Colors the browser toolbar to match your site, with separate light and dark values.
-
Hides content but lets browser search and #links still find and reveal it.
-
Marks places where a long URL or path may wrap, without adding a hyphen.
https://example.com<wbr>/some<wbr>/very<wbr>/long<wbr>/path<wbr>/to<wbr>/a-file.pdf -
Makes a link save the file with a name you suggest, only for same-origin URLs.
-
Gives a visible date a precise machine-readable value for browsers and scripts.
-
Hints that an image can be decoded after the rest of the page has painted.
width="800" height="600" decoding="async"> -
Filters the Network panel down to requests bigger than a size you choose.
larger-than:500k -
Makes Chrome behave as if reduced motion is switched on, to test your CSS.
@media (prefers-reduced-motion: reduce) { .hero { animation: none; }} -
Joins an array into a readable sentence list using the rules of a language.
const cities = ["Leiden", "Delft", "Utrecht"]; -
Sends a message from one browser tab to all other open tabs of the same site.
// in the tab where the user clicks "log out" -
Keeps the original error attached when you catch it and throw a clearer one.
throw new Error("Could not load settings", { cause: err }); -
Sends a small POST request reliably when a visitor leaves or hides the page.
const data = JSON.stringify({ path: location.pathname, seconds: timeOnPage }); -
Creates a promise and hands you its resolve and reject functions to call later.
const { promise, resolve, reject } = Promise.withResolvers(); -
Makes a click-to-expand block in plain HTML, with no JavaScript.
-
Makes a full deep copy of a JavaScript object, including dates, maps and sets.
const copy = structuredClone(original); -
Gives an element a fixed width-to-height ratio with one CSS line.
.video {
Typography 8
-
Short quotes get German, French or English quote marks automatically from the lang attribute.
q { quotes: auto; } -
Keyboard shortcuts get proper markup and can be styled as keys.
kbd kbd { -
Values and their units never end up split across two lines.
20 GB free. See Fig. 3 and page 12.</p> -
A preloaded font arrives before the stylesheet asks for it, instead of being fetched twice.
href="/fonts/source-serif-regular.woff2" -
Colours or replaces the bullets and numbers of a list directly in CSS.
ul li::marker { -
Gives every digit the same width so timers and number columns stop shifting.
font-variant-numeric: tabular-nums; -
Lets the browser hyphenate long words at the end of a line, using the page language.
hyphens: auto; -
A heading that wraps and leaves one short word alone on the second line looks like a mistake, and one line of CSS prevents it. Set text-wrap to balance and…
text-wrap: balance;
Layout and type 3
-
The browser reserves the right space for an image before the file arrives.
alt="Boats in the harbour at sunset"> -
A countdown list without typing the numbers by hand.
-
Lets textareas and text inputs resize to fit what is typed, without JavaScript.
textarea {
Selectors and cascade 3
-
Styles a container while any element inside it has keyboard focus.
.field:focus-within { -
Applies hover effects only on devices that can really hover, not on touch screens.
@media (hover: hover) { -
Applies CSS rules only inside one element, and optionally stops at an inner boundary.
@scope (.card) to (.card-footer) {
Load and performance 1
-
Send many concurrent requests to a URL to see how the server copes
ab -n 200 -c 10 https://example.com/
Nothing in this filter yet.