goldhand/sw-precache-webpack-plugin

How to Initialize Imported Scripts

JackForbes opened this issue · 4 comments

  • I'm submitting a bug report
  • I'm submitting a feature request
  • I'm submitting a support request

webpack version:
1.14

sw-precache-webpack-plugin version:
0.11.4

Question
How can I go about initializing an imported script? Specifically, I'm trying to implement Offline Google Analytics.

There's documentation for importing the script but I'm not sure how to initialize afterward:
importScripts('path/to/offline-google-analytics-import.js'); goog.offlineGoogleAnalytics.initialize();

I also like to know how to initialize the imported Scripts? I am trying to use sw-offline-google-analytics to store analytics in offline mode and send it after coming online.

Any help on this so far?
I have the same issue here...

Can you not initialize the script from the file that is being imported?

p-rk commented

@Garito @JackForbes @krishnappan95
you can do something like this create a js file (example: offline-analytics.js) in your project then add below

importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.6.1/workbox-sw.js');
workbox.googleAnalytics.initialize();

then you in your config include the file

    new SWPrecacheWebpackPlugin({
      cacheId: 'rama',
      filename: 'sw.js',
      minify: true,
      importScripts: [
        'offline-analytics.js'
      ]
   })

Just make sure that you able to serve the offline-analytics.js file from your project