主题: browser
-
浏览器存储:比较 cookie、Web Storage 与 IndexedDB
Cookie 会随每个请求传输,规范要求的容量较小;localStorage 和 sessionStorage 是同步字符串存储,每个源只有数 MiB;IndexedDB 是异步、支持事务的存储,共享源的较大配额。除非获准持久化,否则浏览器存储都是尽力保留,并按源划分。
-
同源策略:源是什么,以及它隔离什么
源由 URL 的协议方案、主机和端口组成。脚本可以读取和修改同源文档、存储及响应;跨源读取默认被阻止,而表单提交等跨源写入,以及图片和脚本等嵌入通常被允许。CORS 放宽读取限制,但仍需 CSRF 防御。
-
Using fetch with timeouts and AbortController
A fetch promise rejects only on network failure, not on HTTP error status, and it has no timeout by itself. Pass an AbortSignal combined from AbortSignal.timeout and a caller's controller, check response.ok, and tell TimeoutError, AbortError, network errors and HTTP errors apart in the catch.
-
Web Vitals:LCP、INP 和 CLS 分别测量什么
Core Web Vitals 是三个真实用户指标:Largest Contentful Paint(最大可见元素的渲染时间,目标 2.5 秒)、Interaction to Next Paint(最长交互延迟,目标 200 毫秒)和 Cumulative Layout Shift(意外位移,目标 0.1)。每项都按页面加载的第 75 百分位评估。
-
Web Push basics: subscriptions, VAPID keys and the push service
A browser subscribes with its vendor's push service and hands the page an endpoint plus keys; the application server POSTs encrypted messages to that endpoint with a TTL header and a VAPID JWT (ES256, aud = push service origin, exp at most 24 hours) whose public key was passed to PushManager.subscribe as applicationServerKey. A 201 means accepted, not delivered.
-
浏览器端到端测试中的稳定选择器与自动等待
不稳定浏览器测试主要有两类原因:选择器失效或匹配错误元素,以及假定时序的固定等待。应按角色、标签或测试 ID 定位,每个定位器恰好匹配一个元素,并通过可重试断言和可操作性检查同步,而不是依赖时间。
-
CSS 布局:何时使用 flexbox,何时使用 grid
Flexbox 是一维模型,沿一行或一列分配空间;grid 是二维模型,同时定义行和列。内容决定尺寸的元素组使用 flexbox,页面与表单结构使用 grid;两者可以组合,使用 gap,并允许元素收缩以避免文本溢出。
-
When does progressive enhancement pay off for an application that needs JavaScript anyway?
Open question: for applications whose core features cannot work without script, which parts still deserve a working no-script or reduced-script path, how often does script fail to run for a real audience, and how should a team decide with data rather than principle?
-
The JavaScript event loop: tasks, microtasks and rendering
JavaScript runs one job at a time; the HTML event loop takes a task, then drains the whole microtask queue (promise reactions, queueMicrotask) before the next task or a rendering opportunity. Long synchronous work and endless microtask chains block input and painting.
机器可读: JSON