Image Story Extension
The Image Story extension allows you to display rich HTML content (stories, descriptions, captions) below images in the lightbox. Content is loaded on-demand and cached for performance.
Installation
Section titled “Installation”ESM (Module Bundlers)
Section titled “ESM (Module Bundlers)”UMD (CDN)
Section titled “UMD (CDN)”Configuration
Section titled “Configuration”getStory (required)
Section titled “getStory (required)”A function that returns a promise resolving to a story object:
StoryResult interface:
maxStoryCache (optional)
Section titled “maxStoryCache (optional)”Maximum number of stories to keep in memory. Default: 5
Features
Section titled “Features”- Rich HTML content - Display formatted text, images, links, etc.
- On-demand loading - Stories are fetched only when needed
- Smart caching - Recently viewed stories are cached
- Auto-sanitization - HTML is automatically sanitized using DOMPurify
- Expandable panel - Users can expand/collapse the story
- Lifecycle hooks - onLoad/onUnload for custom behavior
Usage Examples
Section titled “Usage Examples”Basic Usage
Section titled “Basic Usage”Fetching from API
Section titled “Fetching from API”With Lifecycle Hooks
Section titled “With Lifecycle Hooks”With Static Stories
Section titled “With Static Stories”Styling
Section titled “Styling”The extension includes default styles, but you can customize:
Security
Section titled “Security”The extension automatically sanitizes HTML content using DOMPurify to prevent XSS attacks. However, you should still:
- Validate input on your server
- Use Content Security Policy (CSP) headers
- Sanitize user-generated content before storing
Performance
Section titled “Performance”Caching
Section titled “Caching”Stories are cached in memory to avoid redundant API calls:
Lazy Loading
Section titled “Lazy Loading”Stories are only fetched when the user navigates to an image, not during initialization.
Cache Eviction
Section titled “Cache Eviction”When the cache exceeds maxStoryCache, the oldest entries are evicted (FIFO).
Bundle Size
Section titled “Bundle Size”- ESM: 33.60 KB (10.84 KB gzip)
- UMD: 25.28 KB (9.81 KB gzip)
- CSS: 2.52 KB (0.72 KB gzip)
Note: Includes DOMPurify for HTML sanitization.
Next Steps
Section titled “Next Steps”- Learn about creating custom extensions
- Explore other extensions
- See configuration options