Skip to main content

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 to true to enable)

Asset Loading Process

The optimized asset loading follows this sequence:

  1. Initial Route Request:

    • Intercepts the first GET request
    • Serves index.html from assets regardless of URL
    • Sets flags to track initial page load status
  2. 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
  3. 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

  1. 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
  2. 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"
    }
    }
    }
  3. 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:

  1. Check Logs:

    • Look for "Asset loading stats" in logs
    • Check for failed asset loading attempts
    • Verify MIME type assignment
  2. Configuration Issues:

    • Ensure buildOptimisation is correctly set
    • Verify build assets were copied successfully
  3. Loading Failures:

    • Asset paths may be incorrect
    • Assets might be missing from the build
    • Check for file permission issues
  4. Rebuild When Required:

    • Update your app when static assets change significantly
    • Clear cache when troubleshooting loading issues