You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm really excited about the direction this frontend integration is taking. It covers almost all we need.
There is one piece that is missing and still covered by Webpack: the service worker.
At the moment, I don't know how to manage that, but I will be happy to contribute to it.
Hereafter, an extract of the webpack.config.js and the assets/sw.js files
const{InjectManifest}=require('workbox-webpack-plugin');constWebpackPwaManifest=require('webpack-pwa-manifest');Encore// Usual Webpack config goes here// Plugin for compiling the service worker.addPlugin(newInjectManifest({swSrc: './assets/sw.js',swDest: '../sw.js',maximumFileSizeToCacheInBytes: 50000000,exclude: [/\.map$/,/manifest$/,/\.htaccess$/,/service-worker\.js$/,/sw\.js$/,],}))// Plugin for writing the Progressive Web App manifest.addPlugin(newWebpackPwaManifest({name: 'My App',short_name: 'my-app',description: 'This is my application',filename: "application.json",orientation: "any",display: "standalone",id: "/",start_url: "/app",inject: false,fingerprints: true,ios: true,publicPath: null,includeDirectory: true,background_color: '#ffffff',crossorigin: 'use-credentials',icons: [{src: path.resolve('assets/images/logo.png'),sizes: [48,57,60,72,76,96,114,128,144,152,180,192,256,384,512,1024],// multiple sizes,},{purpose: "maskable",src: path.resolve('assets/images/maskable_logo.png'),sizes: [48,57,60,72,76,96,114,128,144,152,180,192,256,384,512,1024],}],protocol_handlers: [{protocol: "web+app-report",url: "/dashboard/report/%s"},{protocol: "web+app-customer",url: "/dashboard/customer/%s"}]}));//... Export
import{BackgroundSyncPlugin}from'workbox-background-sync';import{pageCache,imageCache,staticResourceCache,googleFontsCache,offlineFallback,warmStrategyCache,}from'workbox-recipes';import{NetworkOnly,CacheFirst,NetworkFirst}from'workbox-strategies';import{precacheAndRoute}from'workbox-precaching';import{registerRoute}from"workbox-routing/registerRoute";import{CacheableResponsePlugin}from"workbox-cacheable-response/CacheableResponsePlugin";import{ExpirationPlugin}from"workbox-expiration/ExpirationPlugin";constPAGE_CACHE_NAME='pages';constFONT_CACHE_NAME='fonts';constSTATIC_CACHE_NAME='assets';constCUSTOM_CACHE_NAME='custom';constIMAGE_CACHE_NAME='images';constOFFLINE_URI='/';constOFFLINE_MAX_RETENTION_TIME=24*60*15;constBACKGROUND_SYNC_QUEUE_NAME='my-app';constwarmCacheUrls=['/','/app',];constbgSyncPlugin=newBackgroundSyncPlugin(BACKGROUND_SYNC_QUEUE_NAME,{maxRetentionTime: OFFLINE_MAX_RETENTION_TIME});registerRoute(/\/app\/.*/,newNetworkFirst({cacheName: CUSTOM_CACHE_NAME,}),'GET');registerRoute(/\/app\/(something|other-things).*/,newNetworkOnly({plugins: [bgSyncPlugin],}),'POST');registerRoute(/\/dashboard\/.*/,newNetworkOnly(),'GET');registerRoute(/\/login/,newNetworkOnly(),'GET');pageCache({cacheName: PAGE_CACHE_NAME});googleFontsCache({cacheName: FONT_CACHE_NAME,});staticResourceCache({cacheName: STATIC_CACHE_NAME,});imageCache({cacheName: IMAGE_CACHE_NAME,maxEntries: 250,maxAgeSeconds: 3600*24*365,});offlineFallback({pageFallback: OFFLINE_URI,});// Cache the underlying font files with a cache-first strategy for 1 year.registerRoute(({request})=>request.destination==='font',newCacheFirst({cacheName: FONT_CACHE_NAME,plugins: [newCacheableResponsePlugin({statuses: [0,200],}),newExpirationPlugin({maxAgeSeconds: 60*60*24*365,maxEntries: 30,}),],}),);precacheAndRoute(self.__WB_MANIFEST);conststrategy=newCacheFirst();warmStrategyCache({urls: warmCacheUrls, strategy});
The application manifest is then declared as a normal header meta tag <link rel="manifest" href="{{ asset('build/application.json') }}">. Icons of all sizes are created.
The compiled service worker (I use Workbox in general) is loaded by the main app.js file as follows:
Honestly, I don't know how to deal with these two files without Webpack.If you have any clue on how to get rid of Webpack for such use case, let me know.
The text was updated successfully, but these errors were encountered:
Hi,
I'm really excited about the direction this frontend integration is taking. It covers almost all we need.
There is one piece that is missing and still covered by Webpack: the service worker.
At the moment, I don't know how to manage that, but I will be happy to contribute to it.
Hereafter, an extract of the
webpack.config.js
and theassets/sw.js
filesThe application manifest is then declared as a normal header meta tag
<link rel="manifest" href="{{ asset('build/application.json') }}">
. Icons of all sizes are created.The compiled service worker (I use Workbox in general) is loaded by the main
app.js
file as follows:Honestly, I don't know how to deal with these two files without Webpack.If you have any clue on how to get rid of Webpack for such use case, let me know.
The text was updated successfully, but these errors were encountered: