Summary
Integrate solidos-lite to embed RDF data directly in HTML responses, eliminating the need for a second HTTP request when viewing resources in the browser.
Current Behavior
Browser → GET /resource (Accept: text/html)
Server → Returns HTML wrapper that loads mashlib from CDN
Browser → mashlib initializes, fetches /resource AGAIN (Accept: text/turtle)
Server → Returns RDF data
Browser → mashlib renders the data
Problems:
- Two HTTP round-trips required
- Cannot work offline after initial load
- Not suitable for static HTML exports
- Latency penalty for every resource view
Proposed Behavior
Browser → GET /resource (Accept: text/html)
Server → Returns HTML with:
- Embedded RDF in <script type="text/turtle"> data island
- solidos-lite shim that intercepts mashlib fetcher
Browser → solidos-lite patches fetcher.load()
Browser → mashlib reads from data island (no network request)
Browser → Renders immediately
How solidos-lite Works
solidos-lite intercepts mashlib RDF fetching by patching fetcher.load:
const originalLoad = fetcher.load.bind(fetcher)
fetcher.load = async function(uri, options = {}) {
const island = findDataIsland(uriStr)
if (island) {
// Parse locally embedded data instead of fetching
$rdf.parse(content, store, baseUri, contentType)
fetcher.requested[baseUri] = "done"
return doc
}
// Fall back to original network fetch
return originalLoad(uri, options)
}
Key interception points:
fetcher.load() - main fetch function
fetcher.nowOrWhenFetched() - callback-based fetching
fetcher.getState() - reports "fetched" for data island URIs
Implementation Plan
Phase 1: Basic Integration
File: src/mashlib/index.js
Update generateDatabrowserHtml() to:
- Accept RDF content as parameter
- Embed content in
<script type="text/turtle" data-uri="..."> tag
- Load solidos-lite from CDN before mashlib
Phase 2: Handler Integration
File: src/handlers/resource.js
Pass RDF content to HTML generator when serving mashlib view.
Phase 3: Content Type Handling
text/turtle → embed directly
application/ld+json → embed as JSON-LD
text/n3 → embed directly
application/rdf+xml → fallback to fetch
Phase 4: Large Resource Handling
const MAX_EMBED_SIZE = 100 * 1024; // 100KB threshold
if (rdfContent.length > MAX_EMBED_SIZE) {
return generateDatabrowserHtml(resourceUrl); // fetch-based
} else {
return generateDatabrowserHtml(resourceUrl, rdfContent, contentType); // embedded
}
Benefits
| Benefit |
Description |
| Performance |
Single HTTP request instead of two |
| Offline Support |
Save HTML file, view offline |
| Static Export |
Generate static HTML sites from Solid data |
| Reduced Server Load |
Half the requests for browser views |
| Better UX |
Faster initial render, no loading flicker |
Considerations
Security
- Embedded content must be properly escaped to prevent XSS
- RDF in
<script> tags is generally safe (not executed as JS)
Caching
- Browser caching differs for embedded vs fetched content
- Consider ETags/Last-Modified for HTML response
Linked Resources
- solidos-lite falls back to network fetch for linked resources
- Only primary resource is embedded
Testing Plan
- Unit Tests: generateDatabrowserHtml() with embedded content
- Integration Tests: Verify single network request in devtools
- Manual Tests: Save HTML, open locally, verify offline rendering
References
Related Issues
LLM-friendly issue for future implementation.
Summary
Integrate solidos-lite to embed RDF data directly in HTML responses, eliminating the need for a second HTTP request when viewing resources in the browser.
Current Behavior
Problems:
Proposed Behavior
How solidos-lite Works
solidos-lite intercepts mashlib RDF fetching by patching
fetcher.load:Key interception points:
fetcher.load()- main fetch functionfetcher.nowOrWhenFetched()- callback-based fetchingfetcher.getState()- reports "fetched" for data island URIsImplementation Plan
Phase 1: Basic Integration
File:
src/mashlib/index.jsUpdate
generateDatabrowserHtml()to:<script type="text/turtle" data-uri="...">tagPhase 2: Handler Integration
File:
src/handlers/resource.jsPass RDF content to HTML generator when serving mashlib view.
Phase 3: Content Type Handling
text/turtle→ embed directlyapplication/ld+json→ embed as JSON-LDtext/n3→ embed directlyapplication/rdf+xml→ fallback to fetchPhase 4: Large Resource Handling
Benefits
Considerations
Security
<script>tags is generally safe (not executed as JS)Caching
Linked Resources
Testing Plan
References
Related Issues
LLM-friendly issue for future implementation.