Yii2 service worker for offline cache PWA

Is there a way to implement a service worker to make your application working offline as described Here at developers.google.com on assets like this:

        namespace app\assets;

        use yii\web\AssetBundle;
        use yii\web\View;

        class AppAsset extends AssetBundle {

          public $sourcePath = '@app/media';

          public $baseUrl = '@app';

          public $js
            = [
              'js/sw.js', //serviceWorker for pwa

          public $css
            = [

          public $depends
            = [

          public $jsOptions
            = [
              'position' => View::POS_END,

Hello Muitosefala,

When it comes to Service Worker, it’s more related to client side scripts i.e JS powered!. The way how you design matters here.

You can use the browsers “IndexedDB” to store the user data temporarily when they’re in offline once they connected to internet just save to your server and flush the local IndexedDB data!. These all should be done through JS and must be registered during service worker registration.

For more info about IndexedDB you can refer here : https://developers.google.com/web/ilt/pwa/working-with-indexeddb

Thanks for your answer!