Skip to content

PWA Configuration and Technical Implementation ​

Overview ​

This document provides technical documentation for the PWA configuration functionality in the PwaSettings module. It describes the components, configuration options, and implementation details for transforming your Laravel application into a Progressive Web App.

Technical Components ​

Models ​

Settings ​

php
namespace Modules\PwaSettings\Models;

// Main configuration model for PWA settings
class Settings extends Model
{
    // Core PWA manifest properties
    public $fillable = [
        'pwa_active',           // Enable/disable PWA functionality
        'name',                 // Full application name
        'short_name',           // Short name for home screen
        'scope',                // PWA scope URL
        'start_url',            // Starting URL when launched
        'display',              // Display mode (standalone, fullscreen, etc.)
        'orientation',          // Screen orientation preference
        'description',          // App description
        'background_color',     // Background color
        'theme_color',          // Theme color for browser UI
        
        // Icon configuration
        'android_icons_size',   // Android icon sizes array
        'ios_icons_size',       // iOS icon sizes array
        'maskable_icons_size',  // Maskable icon sizes array
        
        // Advanced features
        'enable_offline_mode',  // Offline functionality
        'cache_strategy',       // Caching strategy enum
        'enable_install_button' // Show install prompt
    ];
}

Services ​

ManifestService ​

php
namespace Modules\PwaSettings\Services;

// Service for generating PWA manifest
class ManifestService
{
    // Generates the complete manifest.json content
    public function generateManifest(): array;
    
    // Generates icons array for manifest
    private function generateIcons(Settings $settings): array;
    
    // Gets default manifest when PWA is not active
    private function getDefaultManifest(): array;
}

ServiceWorkerService ​

php
namespace Modules\PwaSettings\Services;

// Service for generating service worker
class ServiceWorkerService
{
    // Generates the service worker JavaScript content using Workbox
    public function generateServiceWorker($settings): string;
    
    // Generates minimal service worker when offline mode is disabled
    private function generateMinimalServiceWorker(): string;
}

Controllers ​

ManifestController ​

php
namespace Modules\Pwasettings\Http\Controllers;

// Controller for serving PWA manifest
class ManifestController extends Controller
{
    // Serves the manifest.json file
    public function manifest(Request $request): JsonResponse;
}

PwaController ​

php
namespace Modules\PwaSettings\Http\Controllers;

// Controller for PWA-related endpoints
class PwaController extends Controller
{
    // Serves the service worker script
    public function serviceWorker(Request $request): Response;
}

Configuration Options ​

Display Modes ​

ModeDescriptionUse Case
standaloneApp appears without browser UIMost common PWA mode
fullscreenApp takes full screenGames, media apps
minimal-uiMinimal browser UI shownApps needing some browser features

Orientation Options ​

OrientationDescription
anyNo orientation preference
landscapeLandscape mode only
portraitPortrait mode only

Cache Strategies ​

StrategyDescriptionBest For
CacheFirstServe from cache, fallback to networkStatic assets, images
NetworkFirstTry network first, fallback to cacheDynamic content, API calls
StaleWhileRevalidateServe from cache, update in backgroundFrequently updated content

Manifest Generation Process ​

  1. Settings Retrieval

    • ManifestService retrieves settings from database
    • Uses default values when PWA is not active
  2. Icon Processing

    • Processes Android, iOS, and maskable icon configurations
    • Generates icon entries with proper sizes and purposes
    • Uses fallback icon if no icons are configured
  3. Manifest Assembly

    • Combines all configuration into valid manifest structure
    • Returns JSON response with proper headers

Icon Management ​

The module supports three types of icons:

  • Android Icons: Stored in android_icons_size array field
  • iOS Icons: Stored in ios_icons_size array field
  • Maskable Icons: Stored in maskable_icons_size array field

Icon sizes are configurable through the Filament admin interface and stored as JSON arrays in the database.

Meta Tag Generation ​

The module automatically generates PWA-related meta tags:

Basic PWA Meta Tags ​

html
<meta name="application-name" content="{{ $settings->name }}">
<meta name="description" content="{{ $settings->description }}">
<meta name="theme-color" content="{{ $settings->theme_color }}">
<meta name="msapplication-TileColor" content="{{ $settings->background_color }}">

iOS-Specific Meta Tags ​

html
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<meta name="apple-mobile-web-app-title" content="{{ $settings->short_name }}">

Social Media Integration ​

html
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="{{ $settings->twitter_og_title }}">
<meta name="twitter:description" content="{{ $settings->twitter_og_description }}">
<meta property="og:title" content="{{ $settings->twitter_og_title }}">
<meta property="og:url" content="{{ $settings->twitter_og_url }}">

Database Schema ​

pwa_settings ​

ColumnTypeDescription
idbigintPrimary key
pwa_activebooleanEnable PWA functionality
namestringFull application name
short_namestringShort name for home screen
scopestringPWA scope URL
start_urlstringStarting URL
displayenumDisplay mode
orientationenumScreen orientation
descriptiontextApp description
background_colorstringBackground color hex
theme_colorstringTheme color hex
android_icons_sizejsonAndroid icon sizes array
ios_icons_sizejsoniOS icon sizes array
maskable_icons_sizejsonMaskable icon sizes array
enable_offline_modebooleanOffline functionality
cache_strategyenumCaching strategy
cache_pagesbooleanCache HTML pages
cache_api_requestsbooleanCache API responses
cache_static_assetsbooleanCache CSS/JS/images
cache_max_age_secondsintegerCache expiration time
max_cache_entriesintegerMaximum cache entries
enable_install_buttonbooleanShow install prompt

Integration Points ​

Filament Integration ​

The module integrates with Filament through:

  • SettingsPage: Comprehensive configuration interface
  • PwaSettingsPlugin: Plugin registration and discovery
  • Render Hooks: Install button injection

Route Registration ​

php
// Automatic route registration in ServiceProvider
Route::prefix('pwa')->name('pwa.')->group(function () {
    Route::get('/manifest.json', [ManifestController::class, 'manifest'])->name('manifest');
    Route::get('/sw.js', [PwaController::class, 'serviceWorker'])->name('sw');
});