Phase 8 — Resource Loading + Character Encoding + Real Page Loading#
Implement loading of external CSS stylesheets referenced by <link rel="stylesheet"> elements.
Requirements#
- After HTML parsing, scan the DOM for
<link rel="stylesheet" href="...">elements - Resolve the
hrefattribute against the document's base URL - Fetch the stylesheet using the ResourceLoader
- Parse the fetched CSS text using the
csscrate parser - Merge external stylesheet rules with inline
<style>rules in proper cascade order - Handle
@importrules (fetch and parse imported stylesheets, with depth limit to prevent cycles) - Respect
mediaattribute on<link>(basic:screen,all) - Handle
type="text/css"attribute (default if omitted)
Integration Points#
htmlcrate: extract<link>elements from DOM after tree buildingurlcrate: resolve relative URLsencodingcrate: decode CSS text with correct encodingcsscrate: parse stylesheet textstylecrate: merge rules into cascade
Acceptance Criteria#
- External stylesheets are fetched and parsed
- Rules from external sheets participate in cascade with correct origin/order
- Relative URLs in
hrefare resolved correctly -
@importis followed (with cycle/depth protection, max depth 5) - Missing/failed stylesheet loads are handled gracefully (no crash)
- No external dependencies, no
unsafe - Unit tests with mock/constructed scenarios
Dependencies#
Depends on: Resource loader, CSS parser (already complete)