zmrq / php-pwa
A PHP library for Progressive Web Apps (PWAs)
README
Effortlessly Enable Seamless, Offline-Ready Web Experiences
β¨ Overview
PHP-PWA is a lightweight library that enables your native PHP applications to become Progressive Web Apps (PWAs) without requiring any additional PHP or JavaScript frameworks. With PHP-PWA, your web app can work offline, load faster, and feel like a native applicationβall with simple integration into your existing PHP codebase.
π Features
- β‘ Instant offline support via Service Worker
- π Automatic generation of PWA manifest file (
manifest.json) - π§© Easy integration with native PHP applications (no framework required)
- π¦ Composer-friendly package structure
- π‘οΈ No dependency on any PHP framework
π οΈ Technology Stack
Built with:
π¦ Installation
Install via Composer:
composer require zmrq/php-pwa
βοΈ Usage
-
Enable PWA in your application's root:
<?php use Zmrq\PWA\Pwa; // The 'dir' parameter is the public root directory for PWA assets, default is 'pwa'. Pwa::enable(dir: 'pwa'); // This returns an instance of the manifest class, allowing you to configure the manifest. $manifest = Pwa::enable(dir: 'pwa') ->name('PHP PWA') ->shortName('PWA') ->startUrl('/'); ?>
-
Add the following script to your HTML
<head>:<?= Pwa::renderMetaTags()
-
Add the following script before the closing
</body>tag:<?= Pwa::renderServiceWorker() ?>
π Example Directory Structure
/public
/pwa
βββ logo.png
βββ offline.html
βββ manifest.json
βββ sw.js
βββ index.php
πΌοΈ Offline Page Preview
Below is a preview of the offline page as shown by offline.png:
π€ Contributing
Contributions are welcome! Please fork this repository and submit a pull request.
π License
Licensed under the MIT License.
