5月31日 20:28
What is Web App Manifest? What are its main properties and configurations?
Web App Manifest is a JSON file used to define PWA metadata and installation information. It allows web applications to be installed on devices like native applications.
Basic Structure of Manifest File
json{ "name": "My PWA App", "short_name": "MyPWA", "description": "This is a PWA app example", "start_url": "/", "display": "standalone", "background_color": "#ffffff", "theme_color": "#000000", "orientation": "portrait-primary", "icons": [ { "src": "/icons/icon-192x192.png", "sizes": "192x192", "type": "image/png" }, { "src": "/icons/icon-512x512.png", "sizes": "512x512", "type": "image/png" } ] }
Main Properties of Manifest
1. Application Names
name: Full application nameshort_name: Short application name (displayed below home screen icon)
2. Launch Configuration
start_url: URL when application startsscope: Application scope rangeorientation: Screen orientation (portrait, landscape, etc.)
3. Display Mode
display: Defines how the application is displayedfullscreen: Full screen displaystandalone: Standalone application mode (recommended)minimal-ui: Minimal UIbrowser: Browser mode
4. Visual Configuration
background_color: Splash screen background colortheme_color: Application theme color (affects browser UI)icons: Application icon array
5. Other Properties
description: Application descriptiondir: Text direction (ltr, rtl)lang: Application languagecategories: Application category arrayscreenshots: Application screenshot array
Icon Requirements
Icon Sizes
- 192x192: For Android devices
- 512x512: For iOS devices and some Android devices
- Recommend providing multiple sizes to adapt to different devices
Icon Formats
- Supports PNG, WebP, ICO and other formats
- Recommend using PNG format for best compatibility
Icon Purposes
purposeproperty can specify icon usage:any: General purpose iconmaskable: Maskable icon (adapts to different shapes)monochrome: Monochrome icon
Referencing Manifest
Reference Manifest in HTML:
html<link rel="manifest" href="/manifest.json">
Role of Manifest
- Installation Prompt: Browser displays installation prompt when Manifest is detected
- Home Screen Icon: Defines icon and name displayed on home screen
- Splash Screen: Defines background color and icon of splash screen
- Display Mode: Controls how application is displayed (full screen, standalone, etc.)
- Theme Color: Affects browser address bar and status bar colors
- Application Metadata: Provides application name, description and other information
Best Practices
- Provide Complete Information: Fill in all necessary properties
- Optimize Icons: Provide icons of multiple sizes and purposes
- Set Theme Color: Use brand color as theme color
- Configure Display Mode: Choose appropriate display mode based on application type
- Test Installation: Test installation experience on different devices
- SEO Optimization: Add description and categories properties
- Version Control: Add version number to Manifest for easier updates
Browser Compatibility
- Chrome, Edge, Firefox: Full support
- Safari: Partial support (iOS 11.3+)
- Must be used with HTTPS
Debugging and Validation
Use Chrome DevTools to validate Manifest:
- Open Application panel
- View Manifest tab
- Check for errors or warnings
- Test "Add to home screen" functionality