Network Information
The Network Information component provides access to the Network Information API, allowing your Progressive Web App to detect and respond to changes in the user's network connection. This enables you to create adaptive experiences that optimize content delivery based on connection quality and type.
This component is particularly useful for:
Adaptive content loading based on connection speed
Video/image quality adjustment for bandwidth optimization
Automatic quality degradation on slow connections
Data saver mode detection and optimization
Preloading strategies based on connection type
Network-aware caching policies
Offline/online state detection
User experience optimization for different connection types
Bandwidth-conscious feature toggling
Browser Support
The Network Information API is currently supported in Chromium-based browsers (Chrome, Edge, Opera) and partially in Firefox. Safari does not support this API.
Supported Properties:
effectiveType: Widely supported (Chrome, Edge, Opera, Firefox)downlink: Widely supported (Chrome, Edge, Opera)rtt: Widely supported (Chrome, Edge, Opera)saveData: Widely supported (Chrome, Edge, Opera, Firefox)type: Limited support (Chrome, Edge on some devices)
Always provide fallback behavior for browsers that don't support the Network Information API. The component will emit an unsupported event when the API is unavailable.
Usage
Basic Network Detection
Adaptive Image Loading
Video Quality Adjustment
Conditional Preloading
Data Saver Mode Detection
Network-Aware Feature Toggling
Connection Type Monitoring
Parameters
None
Actions
None - This component automatically monitors network changes and emits events.
Targets
None
Events
pwa--network-information:change
pwa--network-information:changeDispatched when the component is initialized and whenever the browser detects a change in network conditions (e.g., switching from Wi-Fi to cellular, connection quality changes).
Payload: {connection}
The connection object contains:
effectiveType(string): The estimated effective connection typeValues:
'slow-2g','2g','3g','4g'Represents the effective network quality based on observed RTT and downlink values
downlink(number): Estimated downlink speed in megabits per second (Mbps)Example:
10.5means 10.5 Mbps
rtt(number): Estimated round-trip time in millisecondsLower values indicate better latency
Example:
50means 50ms latency
saveData(boolean): Whether the user has enabled data saver mode in their browsertrue: User wants to minimize data usagefalse: Normal data usage
type(string, optional): The connection medium (when available)Values:
'bluetooth','cellular','ethernet','wifi','wimax','none','other','unknown'Not widely supported on all devices/browsers
Example:
pwa--network-information:unsupported
pwa--network-information:unsupportedDispatched when the Network Information API is not supported by the browser.
No payload
Example:
Best Practices
Always provide fallbacks: Not all browsers support this API - design for graceful degradation
Respect Data Saver mode: When
saveDataistrue, minimize data usageDon't rely on exact values: Connection metrics are estimates, not precise measurements
Combine with actual performance: Use alongside Network Timing API for real measurements
Test on real devices: Emulated network conditions may not reflect real-world behavior
Update gradually: Don't make sudden quality changes that disrupt user experience
Cache aggressively: Use the information to inform caching strategies
Monitor changes: Connection can change frequently - handle multiple events
Inform users: Let users know when you're adapting content based on their connection
Allow overrides: Provide manual quality controls for user preference
Connection Type Reference
Effective Types
slow-2g
2000ms
0.05 Mbps
Text-only, extreme optimization
2g
1400ms
0.07 Mbps
Lightweight content, minimal images
3g
270ms
0.7 Mbps
Standard content, compressed media
4g
0ms
∞
Full quality, preloading enabled
Adapting Content by Connection
Complete Example: Adaptive Media Gallery
Troubleshooting
API not supported
Browser: Safari, older browsers
Solution: Always listen for the unsupported event and provide fallback behavior:
Inaccurate estimates
Issue: Connection metrics don't match actual performance
Solutions:
Use metrics as estimates, not absolute values
Combine with actual performance measurements (Resource Timing API)
Track real download times and adjust accordingly
Test on real devices and connections
Connection type unavailable
Issue: connection.type returns undefined
Cause: Many devices don't expose the connection medium
Solution: Rely on effectiveType, downlink, and rtt instead
Frequent quality changes
Issue: Content quality switches too often, disrupting user experience
Solutions:
Implement debouncing to avoid rapid changes
Set thresholds before switching quality
Only change quality at natural breakpoints (page load, user action)
Data Saver not detected
Issue: saveData always returns false
Cause: User hasn't enabled Data Saver in browser settings
Solution: This is expected behavior - only optimize when explicitly requested by the user
Last updated
Was this helpful?