Android Build Optimization
Overview
The Build Optimization feature significantly enhances performance by preloading static assets directly from device storage rather than retrieving them over the network. This approach reduces page load times by approximately 90%, especially for the initial app launch.
Configuration
Configure the build optimization through the config.json
file:
{
"WEBVIEW_CONFIG": {
"android": {
"sdkPath": "/path/to/android/sdk",
"emulatorName": "your_emulator_name",
"buildOptimisation": true,
"cachePattern": "*.png,*.jpg,*.css,*.js",
"buildType": "debug"
}
}
}
Configuration options:
buildOptimisation
: Enable/disable the feature (set totrue
to enable)
Asset Loading Process
The optimized asset loading follows this sequence:
Initial Route Request:
- Intercepts the first GET request
- Serves
index.html
from assets regardless of URL - Sets flags to track initial page load status
Static Resource Loading:
- Checks if requested resources match static file patterns
- Extracts asset path from URL
- Loads resource directly from device storage
- Logs asset loading statistics
Fallback Mechanism:
- If assets can't be loaded locally, falls back to network
- For cacheable network requests, utilizes the WebCacheManager
- Maintains loading statistics for monitoring
Load Time Impact
With Build Optimization enabled:
- Load Time Reduction: ~90% faster page loading
- Network Requests: Near-zero network requests for static assets
- Asset Success Rate: 100% for bundled resources
- Initial Page Loading: Directly from device storage, eliminating network latency
Best Practices
Asset Selection:
- Include critical JS, CSS, and images in your build folder
- Keep bundle size reasonable to avoid large APK sizes
- Consider excluding rarely used resources to optimize size
Development vs. Production:
{
"WEBVIEW_CONFIG": {
"android": {
"buildOptimisation": true, // Enable for production
"buildType": "release", // Use release for production
"cachePattern": "*.png,*.jpg,*.css,*.js"
}
}
}For development:
{
"WEBVIEW_CONFIG": {
"android": {
"buildOptimisation": false, // Disable for faster development builds
"buildType": "debug", // Use debug for development
"cachePattern": "*.png,*.jpg,*.css,*.js"
}
}
}Performance Monitoring:
- Check asset loading statistics in logs
- Monitor cache hit rates
- Track page load times between versions
Troubleshooting
If you encounter issues with asset loading:
Check Logs:
- Look for "Asset loading stats" in logs
- Check for failed asset loading attempts
- Verify MIME type assignment
Configuration Issues:
- Ensure
buildOptimisation
is correctly set - Verify build assets were copied successfully
- Ensure
Loading Failures:
- Asset paths may be incorrect
- Assets might be missing from the build
- Check for file permission issues
Rebuild When Required:
- Update your app when static assets change significantly
- Clear cache when troubleshooting loading issues