Directory
- Welcome
Frame Component
The Frame component provides a robust solution for embedding external content like PDFs, webpages, and other resources with intelligent loading states and optimized performance.
Key Features
-
Smart Loading: Built-in loading indicators
-
Lazy Loading By Default: Optimized performance with configurable preloading
-
Responsive Design: Full-width and height containment
Basic Usage
Embed external content with minimal configuration:
<Frame src="https://example.com/embedded-content" />
Preload Distance
Configure when the iframe should start loading before it enters the viewport:
<Frame src="https://example.com/content" data-preload-distance="200"/>
The data-preload-distance
attribute defines the distance in pixels from the viewport when preloading should begin.
Frame Component Props API
Prop | Type | Default | Description |
---|---|---|---|
src | string | required | URL of the content to embed |
iframeProps | HTMLAttributesWithData<"iframe"> | { loading: "lazy" } | Props passed directly to the iframe element |
preloadDistance | number | Distance in pixels to trigger preloading |
Best Practices
-
Performance Optimization
- Use lazy loading for below-the-fold content
- Set appropriate preload distances for critical content
- Consider the impact on page load time
-
Security Considerations
- Only embed content from trusted sources
- Use appropriate sandbox attributes when needed
- Consider content security policies
-
Accessibility
- Provide title attributes for screen readers
- Ensure embedded content is accessible
- Consider fallback content when appropriate
Common Applications
Limited Time Launch Sale
Start building secure, accessible websites today with our AstroJS starter template. Get instant access to the Frame component and more!
GET 60% OFF!