Irbisa · Cheatsheet
Web Platform & Security
How the browser renders a page, the DOM and events, CSS layout, accessibility, HTTP and caching, XSS, CSP and CORS, cookies, tokens and OAuth, storage
How does event propagation work in the DOM, and what is event delegation?
const list = document.querySelector<HTMLUListElement>('#todos')!; // One listener for every current and future rowlist.addEventListener('click', (event) => { const button = (event.target as Element).closest<HTMLButtonElement>('button[data-id]'); if (!button || !list.contains(button)) return;…What is the difference between
<script>,<script async>and<script defer>?<head> <!-- blocks parsing: avoid in head --> <script src="/legacy.js"></script> <!-- run after parsing, in this order --> <script defer src="/vendor.js"></script>…How does the browser decide which CSS rule wins when several rules match an element?
@layer reset, vendor, app; @layer vendor { #sidebar .button { color: gray; } /* (1,1,0), but in an earlier layer */}…When do you use Flexbox and when CSS Grid?
/* One dimension: a toolbar */.toolbar { display: flex; align-items: center; gap: 8px;}…What is the difference between
localStorage,sessionStorage, cookies and IndexedDB?What is the difference between
GET,POST,PUT,PATCHandDELETE, and which of them are safe and idempotent?Which HTTP status codes does a frontend developer meet most, and what is the difference between 401 and 403, or 301, 302 and 304?
What changed from HTTP/1.1 to HTTP/2 and HTTP/3, and how does it affect bundling and domain sharding?
Given these response headers, which responses does the browser reuse without a request, which does it revalidate, and which does it never store?
GET /assets/index-3f9c1a.jsCache-Control: public, max-age=31536000, immutable GET /index.htmlCache-Control: no-cacheETag: "v42" GET /api/meCache-Control: no-store GET /api/products?page=1Cache-Control: max-age=60, stale-while-revalidate=300What happens when you type a URL into the browser and press Enter?
How does the browser turn HTML and CSS into pixels (the critical rendering path)?
What is the difference between reflow and repaint, and what is layout thrashing?
const items = document.querySelectorAll<HTMLElement>('.item'); // wrong: each write invalidates layout, the next read forces it againitems.forEach((el) => { el.style.height = `${el.offsetWidth / 2}px`;});…In what order does this code log when the user clicks the button?
const outer = document.querySelector('#outer')!;const button = document.querySelector('#outer button')!; outer.addEventListener('click', () => console.log('outer bubble'));outer.addEventListener('click', () => console.log('outer capture'), { capture: true });button.addEventListener('click', () => console.log('button'));document.addEventListener('click', () => console.log('document'));Why does
z-index: 9999sometimes fail to put an element on top?.card { transform: translateY(0); /* creates a stacking context */} .card .tooltip { position: absolute;…What does it take to make a React app accessible?
Find the bug: keyboard and screen reader users cannot open the menu.
function MenuTrigger({ onOpen }: { onOpen: () => void }) { return ( <div className="menu-trigger" onClick={onOpen}> <img src="/icons/menu.svg" /> </div> );}What is ARIA, and when should you not use it?
What is XSS, how does React protect you from it, and where does that protection end?
import DOMPurify from 'dompurify'; function Comment({ html, website }: { html: string; website: string }) { const safeHtml = DOMPurify.sanitize(html); // Allow-list the protocol: escaping does not make a URL safe const safeUrl = /^https?:/i.test(website) ? website : undefined;…What is CORS, what is a preflight request, and how do you fix a CORS error?
// Frontend: send cookies to another originconst res = await fetch('https://api.example.com/orders', { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json' }, // not a simple request: preflight first body: JSON.stringify({ productId: 42 }),…What is a Content Security Policy, and how would you roll one out on an existing React app without breaking it?
import { randomBytes } from 'node:crypto'; // Called for every HTML response: the nonce must be new each timeexport function cspFor() { const nonce = randomBytes(16).toString('base64'); const policy = […What is CSRF, and how do
SameSitecookies and CSRF tokens protect against it?Where should a single-page app store its auth token:
localStorage, a cookie or memory?How does signing in with an external provider work in a single-page app (the OAuth 2.0 authorization code flow with PKCE)?
const AUTH = 'https://auth.example.com';const client = { client_id: 'web', redirect_uri: `${location.origin}/callback` };const b64url = (bytes: Uint8Array) => btoa(String.fromCharCode(...bytes)).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); export async function signIn() {…