requestAnimationFrame(cb) chạy callback trước lần repaint tiếp theo (~16ms), dùng cho animations để sync với display refresh. requestIdleCallback(cb) chạy khi browser idle giữa frames, dùng cho non-urgent tasks như analytics, prefetch. Cả hai quan trọng cho performance.
Lưu ý: requestIdleCallback đã có mặt trên Safari 18+ (2024). scheduler.yield() (Chrome 115+, Stage 2) là cách hiện đại hơn để ngắt long task mà không cần setTimeout(0).
requestAnimationFrame(cb) schedules a callback before the next repaint (~16ms), used for animations to sync with the display refresh rate. requestIdleCallback(cb) runs when the browser is idle between frames, used for non-urgent tasks like analytics and prefetching. Both are important for performance.
Note: requestIdleCallback is available in Safari 18+ (2024). scheduler.yield() (Chrome 115+, Stage 2) is the modern approach for yielding within long tasks without setTimeout(0).