heimrichhannot / contao-pwa-bundle
A bundle to provide progressive web app support for contao.
Installs: 718
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 5
Forks: 3
Open Issues: 5
Type:contao-bundle
Requires
- php: ^7.4 || ^8.0
- ext-fileinfo: *
- ext-json: *
- contao/core-bundle: ^4.9
- heimrichhannot/contao-encore-contracts: ^1.0.2
- heimrichhannot/contao-head-bundle: ^1.2
- heimrichhannot/contao-twig-support-bundle: ^0.2.16|^1.0
- heimrichhannot/contao-utils-bundle: ^2.215
- menatwork/contao-multicolumnwizard: ^3.3
- symfony/framework-bundle: ^4.4 || ^5.4
- symfony/string: ^5.4 || ^6.0
- symfony/translation-contracts: ^1.0 || ^2.0 || ^3.0
- twig/twig: ^1.44 || ^2.14 || ^3.0
Suggests
- minishlink/web-push: Used for sending push notifications. Require as "^5.0".
Conflicts
- minishlink/web-push: <5.0 || >=9.0
- dev-main
- 0.8.18
- 0.8.17
- 0.8.16
- 0.8.15
- 0.8.14
- 0.8.13
- 0.8.12
- 0.8.11
- 0.8.10
- 0.8.9
- 0.8.8
- 0.8.7
- 0.8.6
- 0.8.5
- 0.8.4
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.4
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.0
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.1
- 0.2.0
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-feature/refactoring
- dev-feature/push_notification_popup
- dev-encore
This package is auto-updated.
Last update: 2024-11-03 15:35:31 UTC
README
A bundle to provide progressive web app support for contao.
This bundle is still in beta. Please provide feedback if you use it!
This bundle is using PHP Web Push lib to provide push notifications.
Features
- Create and register manifest file for each page root
- Create and register service worker for each page root
- send custom push notifications from backend
- set an offline fallback page
- Frontend module and content element to subscribe to push notifications
- Install PWA button content element
- Encore Bundle support, including asset precaching
- expandable architecture
Setup
Requirements
- PHP >= 7.4
- Contao >=4.9
- Contao Head Bundle
For web push notifications:
- Composer package
"minishlink/web-push": "^8.0"
(version 5 to 8 are supported) - PHP extensions:
- gmp
- mbstring
- curl
- openssl
Install
-
Install via composer or contao manager
composer require heimrichhannot/contao-pwa-bundle
-
Update your database
First Steps
- Your page template (typically
fe_page.html5
) must support Head Bundle. This means it must output at least$this->meta()
in head section. See Head Bundle readme for more information - If you want to use push notifications, add vapid keys to your config (see Setup -> Vapidkeys)
- Create an PWA Configuration(Backend -> System -> PWA Configuration)
- Add the configuration to a page root (in page settings you find a new section "Progressive Web App", select yes and choose your configuration)
- On saving the page the page manifest and the serviceworker will be generated
- To provide an option to register to your push notifications, add the Push Subscription Button content element or the push notification popup frontend module to your page.
Push Notifications
VAPID keys
You need to add your server vapid keys to your config file, typical in your project config.yml. If you haven't already vapid keys, you can generate in the PWA Bundle backend (Contao Backend -> System -> PWA Configuration -> Control -> Authentication)
huh_pwa: vapid: subject: "mailto:test@example.org" publicKey: "BPZACSEB_Efa3_e2XdVRm4M3Suga2WnhNs9THpVixfScWicSiA3ZYQ3zCG4Uez3EnbL3q-O2RomlZtYejva642M" privateKey: "W0qtmwq0aB47Swmid0uDZyW945p9b5bgv_WmfsmsRHw"
Usage
Regenerate files
You can regenerate all your manifest and service worker files at once from the Pwa Control (Contao Backend -> System -> PWA Configuration -> Control -> Files -> Rebuild files)
There is also an command available: huh:pwa:build
Developers
JS Event
To support custom controls, there are events and event listeners that can be used. All events are dispatched and listen to on document
.
Events
Listener
Complete configuration
huh_pwa: vapid: subject: "mailto:test@example.org" publicKey: "BPZACSEB_Efa3_e2XdVRm4M3Suga2WnhNs9THpVixfScWicSiA3ZYQ3zCG4Uez3EnbL3q-O2RomlZtYejva642M" privateKey: "W0qtmwq0aB47Swmid0uDZyW945p9b5bgv_WmfsmsRHw" push: automatic_padding: 2847 # int (payload size in byte (min 0, max 4078)) or boolean (enable/disable) manifest_path: '/pwa' # where the manifest files should be located within web folder configfile_path: '/pwa' # where the configuration files should be located within web folder
Commands
Add additional head scripts
It is possible to add additional js code to the head section by using the PwaHeadScriptTags
object available available as huh.head.tag.pwa.script
service. Code added with addScript
will be outputted in header section of your page within <script type='text/javascript'>
tags.
Polyfills
Todo
- image size config
- support svg icons
- select pages to precache
- customize add to homescreen and push notification notifications