Performance: Custom document loaders
MEDIUM IMPACT
Custom document loaders affect page load speed and responsiveness by controlling how and when documents are fetched and processed.
import asyncio import aiofiles class GoodLoader: async def load(self): # Loads document asynchronously in chunks data = '' async with aiofiles.open('large_doc.txt', 'r') as f: async for line in f: data += line return data
class BadLoader: def load(self): # Loads entire document synchronously with open('large_doc.txt', 'r') as f: data = f.read() return data
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous full document load | Minimal DOM nodes | 0 reflows | Blocks paint until load completes | [X] Bad |
| Asynchronous chunked document load | Minimal DOM nodes | 0 reflows | Non-blocking paint, faster LCP | [OK] Good |